如果没有自动引用计数,您在添加新类时经常会编写这样的代码:
假设类名是“Foo”
+ (id) foo
{
return [[[self alloc] init] autorelease];
}
- (id) init
{
self = [super init];
// do some initialization here
return self;
}
那么,你应该如何为 arc 写这个?就像下面的代码一样?
+ (id) foo
{
return [[self alloc] init];
}
- (id) init
{
self = [super init];
// do some initialization here
return self;
}