Bachalo
Bachalo

Reputation: 7219

Where to initialize a NSMutableArray?

having an issue using a NSMutableArray;

In my implementation file applicationDidFinishLaunching method I have

_imgArray = [NSMutableArray array];

and _imgArray is defined in my .h file as

NSMutableArray *_imgArray;

After populating it, it traces out correctly.

The problem is, in another method in my implementation file, I can't seem to acces the _imgArray array. It traces out to

_imgArray=  ar.lproj

What gives?

Upvotes: 0

Views: 244

Answers (1)

Rob Napier
Rob Napier

Reputation: 299683

I'm surprised you're not crashing. You aren't retaining the array when you assign it to _imgArray, so by the second event loop, it's pointing to unallocated memory.

Don't mess with your ivars directly. Use accessors (@property). And study the Memory Management Programming Guide.

Upvotes: 1

Related Questions