When is NSCopying needed?

前端 未结 3 2076
Happy的楠姐
Happy的楠姐 2021-02-19 23:34

I know it\'s needed if your object will be used as a key in an NSDictionary. Are there any other times like this that NSCopying is required?

If I think I don\'t need my

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-20 00:11

    Think of the NSCopying protocol as the objective-C version of cloning routines. If a caller was to clone your object, what is the behavior you would want? If your object is solely composed of primitive types, then you don't need to worry about this. But if you have any complex types as members, you might want to clone/copy them instead of passing simple references to them.

提交回复
热议问题