Re: Read-only properties
Re: Read-only properties
- Subject: Re: Read-only properties
- From: Roland King <email@hidden>
- Date: Sun, 12 Oct 2008 23:56:42 +0800
well first off you're returning an NSArray which is immutable, so
nobody can change the actual array itself, ie add or delete members
(unless of course you really actually return a mutable one and the
caller ignores the warnings and mutates it). If however you don't want
the caller to modify the properties of the objects *in* the array,
then unless those objects are immutable, returning a copy of the array
won't help you anyway. Remember an array of objects is just an array
of pointers to the objects in the array, a normal copy of that just
copies the pointers and you can copy the array itself as much as you
like and the objects inside it are still mutable.
So .. if you really don't want the objects themselves mutated you
either need to make them immutable or take a look at deep copying them.
On Oct 12, 2008, at 11:44 PM, DKJ wrote:
I'd like to have something like this in my class:
@property(readonly) *NSArray myArray;
But I don't want any of the individual objects in the array to be
modified, so I'd like to return a copy of the array. Is there a way
of getting @synthesise to ensure this? Or do I need to write my own
getter method?_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden