objective c - Calling NSMutableArray:addObject is resulting in an unrecognized selector exception -
i'm getting unrecognized selector exception attempting call addobject on array. array nsmutablearray, not nsarray. don't understand why happening.
i have following classes:
@interface : nsobject @property (nonatomic, copy) nsmutablearray* children; - (id) init; - (void) addchild: (a*) child; @end @interface b : - (id) init; @end @implementation - (id) init { self = [super init]; return self; } - (void) addchild: (a*) child { [self.children addobject:child]; } @end @implementation b -(id) init { self = [super init]; if (self != nil) { self.children = [[nsmutablearray alloc] init]; } return (self); }
then if create object of type b , call [b addchild: anobject] i'm getting unrecognized selector , don't understand why.
the output is:
2013-04-08 14:31:08.046 otest[13381:7e03] -[__nsarrayi addobject:]: unrecognized selector sent instance 0x17759c0
what problem?
tia
(please focus on actual code , problem, not side discussions why i'm not allocating array in a's init, unless relevant. want understand why code stands does't work. thanks).
by declaring array storage qualifier copy
instead of strong
, mutable array copied on assignment , turned immutable nsarray.
Comments
Post a Comment