Reputation: 43401
Firstly I would like confirmation that I have understood NSCopying correctly ...
In order to use a simple NSObject subclass as a key in an NSDictionary I must have it implement the NSCopying protocol. In the copied instance's copyWithZone method I must alloc/init a new instance of my class, set its properties to be identical to the copied instance and return it.
Secondly, why does an NSDictionary use a copy of the instance added to it rather than the instance itself?
Upvotes: 1
Views: 2730
Reputation: 19618
Upvotes: 1
Reputation: 15376
The subclass does not need to implement NSCopying
if it is the object, the key should usually be NSString
s, which are copied.
Upvotes: 3