• 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: how to combine addObject with Object instantiation?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to combine addObject with Object instantiation?


  • Subject: Re: how to combine addObject with Object instantiation?
  • From: Chris Espinosa <email@hidden>
  • Date: Mon, 4 May 2009 13:09:33 -0700


On May 3, 2009, at 12:53 PM, Sandy Santra wrote:

After 

NSMutableArray *myArray = [NSMutableArray array];

Is there any way to combine these two lines:

NSString *myName = @"Joe";
[myArray addObject:myName];

into one line?

I keep thinking there's a way to use 

[myArray addObject:[instantiation of some object]];

to add all types of objects to a mutable array, but can't seem to figure out how to combine statements.

I think what you're looking for is

[myArray addObject:@"Joe"];

as the @" " string scalar is the instantiation of the object.  The compiler creates it at compile time, stores it in your binary, and holds a pointer to it, which is equivalent to any other immutable NSString*.

Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >how to combine addObject with Object instantiation? (From: Sandy Santra <email@hidden>)

  • Prev by Date: Re: Skipping warning messages in gdb
  • Next by Date: Re: Couldn't find minimal bounds for "_sigtramp" - backtraces may be unreliable
  • Previous by thread: how to combine addObject with Object instantiation?
  • Next by thread: Re: how to combine addObject with Object instantiation?
  • Index(es):
    • Date
    • Thread