Why does this work:
self.array = newArray;
But this doesn’t:
[[self mutableArray] addObject:object];
Meaning, why do I need to init the NSMutableArray for it to work when I don’t have to init the NSArray?
EDIT: Hops this is clearer guys.
Interface:
@interface Foo : UIViewController {
}
@property (nonatomic, retain) NSArray *array;
@property (nonatomic, retain) NSMutableArray *mutableArray;
@end
Implementation:
@implementation Foo
@synthesize array;
@synthesize mutableArray;
- (void)viewDidLoad {
[super viewDidLoad];
self.array = [Class returningAnArray];
[[self mutableArray] addObject:objectIHaveOmittedTheCode];
}
@end
In this line, you are assigning already created object to
self.array. So, you’ve no need to create it.But in this line you are trying to add an object to a array which is not created actually. If you don’t create the array, it will be
nil, and sending message to nil won’t take any effect.