objective c - simple NSMutable array question -
umm simple question here:
i have instance of nsmutablearray declared in header
nsmutablearray *day19; @property (nonatomic, retain) nsmutablearray *day19
implementation:
@synthesize day19;
in viewdidload
self.day19 = [[nsmutablearray alloc] init];
in mymethod want add objects array i:
nsobject *newobject = [[nsobject alloc] init]; [day19 addobject:newobject];
however... when check day19 array there nothing in it. if conversely add newobject temparray within mymethod scope , set day19 array temparray, day19 has objects.
super basic know must confused morning or something...
thanks help
in viewdidload
self.day19 = [[nsmutablearray alloc] init];
in mymethod want add objects array i:
nsobject *newobject = [[nsobject alloc] init]; [day19 addobject:newobject];
however... when check day19 array there nothing in it. if conversely add newobject temparray within mymethod scope , set day19 array temparray, day19 has objects.
let me guess: checked array code this:
nslog(@"day19 contains %lu objects", [day19 count]);
remember message nil
nothing , returns nil
, 0
, or 0.0
. that's why output said 0 objects: don't have array in first place. probable reason viewdidload
hasn't been called yet, have not yet created mutable array.
it's possible have array (i.e., view has been loaded) @ time examine array, didn't have array yet (the view hadn't been loaded yet) @ time tried add array, addobject:
message fell on deaf ears.
consider creating array earlier. should creating in init
or initwithcoder:
.
a third possibility examined array before ever added it. make sure log or break @ both points, know 1 happened first.
whatever problem is, need either assign array instance variable, not property, or autorelease array before assigning property. otherwise, you're over-retaining array, means leak later on. need review memory management programming guide cocoa.
Comments
Post a Comment