• 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: Pierce Freeman <email@hidden>
  • Date: Wed, 01 Apr 2009 17:00:59 -0700
  • Thread-topic: NSMutableArray is null?

Yeah, it helps a lot... And hopefully anyone that has this problem will look
at this before writing to any support site. :)


On 4/1/09 8:06 AM, "I. Savant" <email@hidden> wrote:

> 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

References: 
 >Re: NSMutableArray is null? (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: Double Clicks in an NSTextView.
  • Next by Date: Re: How to detect curly quotes
  • Previous by thread: Re: NSMutableArray is null?
  • Next by thread: Handling List of Hardware Devices in NSTableView w/ Asynchronous Updates
  • Index(es):
    • Date
    • Thread