Say I wanna create an array of images and i used this:
NSMutableArray *images = [[NSMutableArray alloc]init];
what role does init really play here? won’t it work if I simply use:
NSMutableArray *images = [NSMutableArray alloc];
Please help. Thanks.
No, you absolutely cannot just say
[NSMutableArray alloc]. Calling a method on the results of sending+allocto any class is absolutely incorrect unless that method is one of the-init...methods. All+allocdoes is reserve the memory for the object. It’s basically equivalent to callingcalloc(sizeof(class), 1). The-initmethod is crucial to actually initialize the object into a working state.