tags:

views:

32

answers:

2

Hi,

Was just wondering, which way is better to fully initialise an object:

NSString *myString = [[NSString alloc] init]; 

OR

NSString *myString = [NSString new]; 

thanks

+3  A: 
NSString *myString = [[NSString alloc] init];

This is the preferred way. The majority of code I have seen for iPhone does not use new. Don't for get to release it if you use alloc then init.

Daniel A. White
A: 

There is absolutely no difference at all between new and alloc+init; new is just a "convenience allocator." That said, one typically sees alloc+init used more than new, simply for the sake of consistency.

anshuchimala