Proton
Proton

Reputation: 1365

alloc initWithObjects vs arrayWithObject

I don't understand why if I write these code

icons = [[NSArray alloc] initWithObjects:
             @"appointment",
             @"work",
             @"anniversary",
             @"me",
             nil];

the app crashed. But then I replaced by these code

icons = [NSArray alloc] arrayWithObjects:
             @"appointment",
             @"work",
             @"anniversary",
             @"me",
             nil];

and the app did't crash. But there is the same affect between these methods ! I don't know why ? Can u help me ?

Upvotes: 2

Views: 1176

Answers (1)

Lalit
Lalit

Reputation: 264

  1. initWithObjects method means you have to release the object of array whenever this is not required as this is instance method and for more details click:

  2. arrayWithObjects method means you don't need to release the object of array whenever this is not required as this is class method and for more details click:

If you are not clear with the points so revert me..

Upvotes: 1

Related Questions