In my .h file I have a NSMutableArray *locationsArray defined with a property as follows
@property (nonatomic, retain) NSMutableArray *locationsArray
In my .m file I was displaying a table view, this loaded fine until I tried to roll-up at which point I it crashed with bad access. This was due to the locationsArray not being retained.
This line of code fixed my problem in the .m
locationsArray = [[Locations loadLocations] retain] (#1)
This line of code also fixed the same problem
self.locationsArray = Locations.loadLocations (#2)
I have a couple of questions I need clarification on
- is this the correct way to set this value, should I be doing an
alloc
init
,alloc initwithArray
? - Comming from a java world I understand
self
is this, or at least I thought I did...What is different in objective C that thelocationsArray
without theself
is not being retained without me adding the retain.
Obviously I got it working but it took as while and am still a little confused as to why. any help would be appreciated.