문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top