There are two classes, let's call them Class A and Class B.
Also, in class B, there's a NSMutableArray called arrayB.
@interface A {
// for reference functions in B
B *obj;
}
@property (assign) B *obj;
- (void) addObject: (id) objectB;
And I access B by calling:
obj = [[B alloc] init];
Here's definition of B:
@interface B {
NSMutableArray *arrayB;
}
@property (assign) NSMutableArray *arrayB;
- (void) printArray;
Now, I tried to add objects to arrayB by functions of A:
[self addObject: objectB]
- (void) addObject: (id) objectB {
[obj.arrayB addObject:objectB];
NSLog(@"%@", obj.arrayB);
// here prints arrayB with objectB
}
However when I tried to access the objects again in B:
[self.obj printArray];
- (void) printArray {
NSLog(@"%@", arrayB);
// now it prints an empty array
}
I have no clue what happened here...
Objects will be auto-retained by NSMutableArray's addObject, don't they?
Why it becomes empty every time? >_<
Please help me, thanks!