Re: Setting the value of an array element
Re: Setting the value of an array element
- Subject: Re: Setting the value of an array element
- From: Jens Alfke <email@hidden>
- Date: Thu, 17 Apr 2008 09:38:59 -0700
On 17 Apr '08, at 9:15 AM, Johnny Lundy wrote:
NSArray says you can change the values of elements, but not add/
subtract/replace elements.
Nope; NSArrays are completely immutable. To make any modifications you
first have to make a mutable copy, and then modify that. (The same
goes for NSDictionary, NSSet and NSString.) You might want to re-read
the conceptual overview of Cocoa collections.
My confusion is that there is no setValue:forIndex:. There is only
setValue: forKey: , but arrays do not have keys.
setValue:forKey: has nothing to do with the contents of the array —
it's a generic method inherited from NSObject; it's part of Key-Value
Coding, a higher-level mechanism of getting and setting properties of
object. About the only key that's applicable to an NSArray is its
count, and trying to set the value of that on an immutable array would
raise an exception.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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