Hi,
Was just wondering, which way is better to fully initialise an object:
NSString *myString = [[NSString alloc] init];
OR
NSString *myString = [NSString new];
thanks
Hi,
Was just wondering, which way is better to fully initialise an object:
NSString *myString = [[NSString alloc] init];
OR
NSString *myString = [NSString new];
thanks
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
.
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.