使用alloc init而不是新的学习目标-C和读取示例代码时,我注意到对象通常是使用这种方法创建的:SomeObject *myObject = [[SomeObject alloc] init];而不是:SomeObject *myObject = [SomeObject new];正如我所读到的,这是否有其原因?
3 回答
![?](http://img1.sycdn.imooc.com/545862370001b03502200220-100-100.jpg)
慕田峪4524236
TA贡献1875条经验 获得超5个赞
#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...
![?](http://img1.sycdn.imooc.com/545868330001e54e02200220-100-100.jpg)
桃花长相依
TA贡献1860条经验 获得超8个赞
+new
+alloc/-init
NSObject
+new
+new
+new
.
- 3 回答
- 0 关注
- 397 浏览
添加回答
举报
0/150
提交
取消