• 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: Gregory Weston <email@hidden>
  • Date: Thu, 17 Apr 2008 12:42:12 -0400

Johnny Lundy wrote:

I imagine this is a very dumb question, but I am perplexed.

NSArray says you can change the values of elements, but not add/
subtract/replace elements.

Right. Meaning if a contained object it mutable, you can mutate it and the NSArray won't care.


Let's say I have an NSArray @"Tom", @"Dick", @"Harry", nil

And I want to change Tom and Dick to Mutt and Jeff.

Is my only option to make it a MutableArray and use
replaceObjectAtIndex:0 and :1 with @"Mutt" and @"Jeff"?

Only? No, but that'd be the sensible, straightforward way (presuming those strings are not mutable).


Is there a way just to set the value of an array element without
replacing it?

The question's not really meaningful because there's no such concept as an 'unset' element in an NSArray. If an array has some content at index N it also has content in every index in [0,N-1]. So there's no distinction between setting the value at index N and replacing the value at index N.
_______________________________________________


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


  • Prev by Date: Re: Setting the value of an array element
  • Next by Date: RE: -charactersIgnoringModifiers and the shift key
  • Previous by thread: Re: Setting the value of an array element
  • Next by thread: Simulating menu bar blink in Cocoa
  • Index(es):
    • Date
    • Thread