My colleague just ran into an issue with a synthesized property of type
NSMutableDictionary*, where after he assigned a value to the property, the
property’s value was no longer mutable:
@interface Foo
@property (copy) NSMutableDictionary* moot;
@end
…
// foo is an instance of Foo
foo.moot = [NSMutableDictionary dictionaryWithObject: @“hi” forKey:
@“greeting”];
foo.moot[@“greeting”] = @“bye”; // EXCEPTION RAISED
The exception occurs because the value of foo.moot is now a non-mutable
NSDictionary.
The culprit seems to be the ‘copy’ modifier in the property declaration. The
synthesized setter method is using -copy instead of -mutableCopy, so the object
stored into the instance variable is no longer a mutable dictionary.
So … is this a bug in the compiler, or just a weird edge case one needs to be
aware of when using properties of mutable types?
—Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/objc-language/archive%40mail-archive.com
This email sent to [email protected]