使用alloc init而不是新的学习目标-C和读取示例代码时,我注意到对象通常是使用这种方法创建的:SomeObject *myObject = [[SomeObject alloc] init];而不是:SomeObject *myObject = [SomeObject new];正如我所读到的,这是否有其原因?
3 回答

皈依舞
TA贡献1851条经验 获得超3个赞
#import "InitAllocNewTest.h"@implementation InitAllocNewTest+(id)alloc{ NSLog(@"Allocating..."); return [super alloc];}-(id)init{ NSLog(@"Initializing..."); return [super init];}@end
[[InitAllocNewTest alloc] init];
[InitAllocNewTest new];
2013-03-06 16:45:44.125 XMLTest[18370:207] Allocating... 2013-03-06 16:45:44.128 XMLTest[18370:207] Initializing...

湖上湖
TA贡献2003条经验 获得超2个赞
+new
+alloc/-init
NSObject
+new
+new
+new
.
- 3 回答
- 0 关注
- 424 浏览
添加回答
举报
0/150
提交
取消