使用alloc init而不是新的學(xué)習(xí)目標(biāo)-C和讀取示例代碼時(shí),我注意到對(duì)象通常是使用這種方法創(chuàng)建的:SomeObject *myObject = [[SomeObject alloc] init];而不是:SomeObject *myObject = [SomeObject new];正如我所讀到的,這是否有其原因?
3 回答

蕪湖不蕪
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
#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貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
+new
+alloc/-init
NSObject
+new
+new
+new
.
- 3 回答
- 0 關(guān)注
- 949 瀏覽
添加回答
舉報(bào)
0/150
提交
取消