使用alloc init而不是新的学习目标-C和读取示例代码时,我注意到对象通常是使用这种方法创建的:SomeObject *myObject = [[SomeObject alloc] init];而不是:SomeObject *myObject = [SomeObject new];正如我所读到的,这是否有其原因?
3 回答
LEATH
TA贡献1936条经验 获得超6个赞
#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贡献2051条经验 获得超10个赞
+new
+alloc/-init
NSObject
+new
+new
+new
.
- 3 回答
- 0 关注
- 367 浏览
添加回答
举报
0/150
提交
取消