Reputation:
Was just wondering, which way is better to fully initialise an object:
NSString *myString = [[NSString alloc] init];
OR
NSString *myString = [NSString new];
thanks
Upvotes: 0
Views: 67
Reputation: 2800
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.
Upvotes: 0
Reputation: 190907
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
.
Upvotes: 3