• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Setting the value of an array element
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Setting the value of an array element (From: Johnny Lundy <email@hidden>)

  • Prev by Date: Re: -charactersIgnoringModifiers and the shift key
  • Next by Date: Re: Setting the value of an array element
  • Previous by thread: Setting the value of an array element
  • Next by thread: Re: Setting the value of an array element
  • Index(es):
    • Date
    • Thread