0

I am on objective-c, macOS.

I have an options Dictionary declared like this

@property NSMutableDictionary* options

Now the object containing the dictionary needs to be copied with copyWithZone including the options.

I can invoke "copy" on the dictionary. But how do i make sure that every object added to the dictionary (which basically can be any kind of object), complies to the NSCopying Protocol?

Something like

@property NSMutableDictionary* <NSCopying> options

Can i add something to the property declaration (that i didn't find out yet) or do i need to subclass NSDictionary (which i most likely want to avoid)

Regards

Pat

Pat_Morita
  • 3,355
  • 3
  • 25
  • 36
  • The copy() method is defined for all objects inheriting from NSObject and simply invokes copy(with:) with the default zone. https://developer.apple.com/documentation/foundation/nscopying Every object in dictionary has to be subclass of NSObject – Marek H Aug 08 '21 at 17:07
  • 1
    Also look at https://stackoverflow.com/questions/5453481/how-to-do-true-deep-copy-for-nsarray-and-nsdictionary-with-have-nested-arrays-di Don't forget there is deep and shallow copy. – Marek H Aug 08 '21 at 17:15
  • what about `@property (copy) ... ` – Ol Sen Aug 08 '21 at 17:36
  • How about an Options class instead of a `NSMutableDictionary`? – Willeke Aug 09 '21 at 07:39
  • How about a method to add options? – Willeke Aug 09 '21 at 07:42

0 Answers0