> On 19 May 2015, at 00:48, Jens Alfke <[email protected]> wrote: > > 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?
It’s just the way it is. I figure ‘twould be a whole heap of mess if the compiler were to somehow become aware that the property type is a mutable object, and so therefore needs to me mutably copied instead. _______________________________________________ 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]
