On Nov 18, 2010, at 5:35 AM, Remco Poelstra wrote: > Hi, > > I've a object like to following: > @interface <Proto> { > NSMutableArray *items; > } > @property (nonatomic,readonly) NSMutableArray *items; > @end > > I also have a protocol as follows: > @protocol Proto > @property (nonatomic,readonly) NSArray *items; > @end > > I of course want the items to be read only for the outside world, but the > object itself should be able to modify it. Now the compiler complains about > the properties not matching. How should I solve this? Make a custom getter > that returns an immutable array? Make the property refer to a mutable array? > Make the property an immutable array and make copies of the array while > modifying it?
The ivar type and the property type don't have to match. In fact, there does not need to be any ivar backing whatsoever to properties. Change your property declaration to NSArray *, and implement the getter with [[array copy] autorelease] or similar. You don't have much choice if you want a public immutable, but private mutable. Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com