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" <idiotsavant2...@gmail.com> wrote: > On Wed, Apr 1, 2009 at 10:33 AM, Pierce Freeman > <piercefreema...@comcast.net> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com