Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top