我刚刚阅读了Craig Hockenberry的一篇关于ARC 和 copy的简短博客文章。我现在的问题是传递给分配给实例变量的初始化程序的参数是否应该始终使用copy
?还是取决于实例变量的类型?
#import "MyObject.h"
@implementation MyObject {
SomeType *_ivar1;
SomeOtherType *_ivar2;
}
-(id)initWithParam1:(SomeType *)param1 andParam2:(SomeOtherType *)param2
{
if ((self == [super init])) {
_ivar1 = [param1 copy]; // Always good
_ivar2 = [param2 copy]; // practice?
}
return self;
}
@end