Suppose we have simple NSDictionary class, can one of its objects be an NSMutableDictionary object? When we edit a value within the NSMutableDictionary object, we are only editing values of the object of NSDictionary. Since we are not editing the object of NSDictionary, should it be a problem for the non-mutable NSDictionary class?
Suppose we have simple NSDictionary class, can one of its objects be an NSMutableDictionary
Share
The mutability of a collection class refers only to the ability to modify the collection as a whole, not the members. The collection in fact just consists of pointers to the objects it contains; nothing about them is changed. Putting an object inside an immutable collection does not change the object’s own ability to be modified.
So, yes, you can modify an
NSMutableDictionaryinside anNSDictionary, without difficulty.Likewise for any object (which allows modification) contained inside any immutable collection: