• 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: NSMutableArray is null?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableArray is null?


  • Subject: Re: NSMutableArray is null?
  • From: "I. Savant" <email@hidden>
  • Date: Wed, 1 Apr 2009 11:06:38 -0400

On Wed, Apr 1, 2009 at 10:33 AM, Pierce Freeman
<email@hidden> wrote:

> Yeah, I finally figured that out. ;) It now works like a charm.

  Just for completeness, the plain-language concept to remember is:

// "Let there be an NSMutableArray pointer named 'globalVariable'."
NSMutableArray * globalVariable;

... and ...

// "Create an NSMutableArray instance and assign it to the
'globalVariable' pointer
// ... so when I talk to 'globalVariable', I mean this instance of
NSMutableArray."
globalVariable = [[NSMutableArray alloc] init];

  By contrast, when you're creating objects inside a method (temporary
objects whose scope is limited to that method), do this all in one go:

NSMutableArray * myTemporaryArray = [[NSMutableArray alloc] init];

  - or, more simply -

NSMutableArray * myTemporaryArray = [NSMutableArray array];

  ... then you'll use it then let it die, or hand it off to someone else.

  However, since you're creating an instance variable in your class,
you declare the pointer in your header and then create an array and
assign it to the pointer somewhere in your implementation. The most
likely place (arguably by best practice) would be the class's -init
method, since you want a mutable array ready for use when an instance
of your class is created (allocated and initialized).

   I hope that helps a bit.

--
I.S.
_______________________________________________

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

  • Follow-Ups:
    • Re: NSMutableArray is null?
      • From: Pierce Freeman <email@hidden>
References: 
 >Re: NSMutableArray is null? (From: Pierce Freeman <email@hidden>)

  • Prev by Date: Re: Handling List of Hardware Devices in NSTableView w/ Asynchronous Updates
  • Next by Date: Re: Bindings and MenuItems
  • Previous by thread: Re: NSMutableArray is null?
  • Next by thread: Re: NSMutableArray is null?
  • Index(es):
    • Date
    • Thread