Question

Is NSMutableArray *myArray = [[NSMutableArray alloc] init]; any more or less correct than NSMutableArray *myArray = [NSMutableArray new]; in terms of style or efficiency?

Was it helpful?

Solution

Actually both are used to initialize the new object. new will also do allocate and initialize. But the apple recommends that call alloc first, then after invoke the init method. Thats why we are using [[NSMutableArray alloc] init]

Anyway, there is no big difference here

OTHER TIPS

Neither is "more correct," and in fact they are functionally equivalent, but alloc is much more common than new since custom initialization is always done through initWith...-style methods. So it's hard to say something is stylistically correct, but new is certainly less stylistically standard in modern Objective-C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top