一般如果只是 alloc init 那么 用new 是一样的
SomeObject*myObject =[[SomeObject alloc] init];
SomeObject*myObject =[SomeObjectnew]; 即上述两种情况是一样的!
#import "InitAllocNewTest.h"@implementation InitAllocNewTest+(id)alloc{ NSLog(@"Allocating..."); return [super alloc];}-(id)init{ NSLog(@"Initializing..."); return [super init];}@endIn main function both statements:[[InitAllocNewTest alloc] init];and[InitAllocNewTest new];result in the same output:2013-03-06 16:45:44.125 XMLTest[18370:207] Allocating...2013-03-06 16:45:44.128 XMLTest[18370:207] Initializing...
Some selected ones are:
- new doesn't support custom initializers (like initWithString)
- alloc-init is more explicit than new