我有一个关于与内存管理重叠的初始化程序的问题。我相信这是一个功能完善的初始化程序(即使它在不鼓励的 init 方法中调用 setter)。. .
@synthesize age = _age, name = _name, delegate = _delegate;
- (id)initWithName:(NSString *)name Age:(int)age delegate:(MyDelegateClass *)delegate
{
if (self = [super init]) {
[self setName:name];
[self setAge:age];
[self setDelegate:delegate];
}
return self;
}
但是这个初始化器呢?我需要为这些 ivars 分配内存还是像这样开箱即用?
- (id)initWithName:(NSString *)name Age:(int)age delegate:(MyDelegateClass *)delegate
{
if (self = [super init]) {
_name = name;
_age = age;
_delegate = delegate;
}
return self;
}