Suggest the best way of initialization of array ( or other objects )

后端 未结 4 689
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 09:07

I am a bit confused in the following two ways of initialisations.....

Way 1:

- (void) myMethod{

    NSArray *myArray = [[NSArray alloc] initWithObje         


        
4条回答
  •  春和景丽
    2021-01-15 09:41

    as i know,

    [NSArray arrayWithObjects:obj1,obj2,nil];
    

    returns an autoreleased object, smth like

    [[[NSArray alloc] initWithObjects:obj1,obj1,nil] autorelease];
    

    and I prefer not to manage memory with autorelease pool. maybe it's just a prejudice))

提交回复
热议问题