role of init plays when creating an array

Sah*_*ary -2 xcode cocoa-touch objective-c

Say I wanna create an array of images and i used this:

NSMutableArray *images = [[NSMutableArray alloc]init];
Run Code Online (Sandbox Code Playgroud)

what role does init really play here? won't it work if I simply use:

NSMutableArray *images = [NSMutableArray alloc];
Run Code Online (Sandbox Code Playgroud)

Please help. Thanks.

Lil*_*ard 5

不,你绝对不能说[NSMutableArray alloc].除非该方法是方法之一,否则调用发送+alloc任何类的结果的方法是绝对不正确的-init....所有这些+alloc都是为对象保留内存.它基本上等同于召唤calloc(sizeof(class), 1).该-init方法对于将对象实际初始化为工作状态至关重要.