重写init方法时,出现:Cannot assign to 'self' outside of a method in the init family 。原因:只能在init方法中给self赋值,Xcode判断是否为init方法规则:方法返回id,并且名字以init +大写字母开头+其他 为准则。
例:- (id)initWithName:(NSString *)name andAge:(int)age andHeight:(double)height
{
if (self = [super init])
{
_name = name;
_age = age;
_height =height;
}
return self;
}
|
|