ios - cannot assign to 'self' outside of a method in the init family

时间:2014-06-26 15:17:17   收藏:0   阅读:638

今天重写 - (id) initwithId:(NSInteger *)word_id word:(NSString *)word detail:(NSString *)detail方法时不注意将init后面的第一个字母写成了小写,在这个方法里面又调用父类的初始化方法(self = [super init];)时会报错,错误信息如下:error:Cannot assign to ‘self‘ outside of a method in the init family

原因:只能在init方法中给self赋值,Xcode判断是否为init方法规则:方法返回id,并且名字以init +大写字母开头+其他  为准则。例如:- (id) initWithXXX;

解决方法:init后面第一个字母大写- (id) initWithId:(NSInteger *)word_id word:(NSString *)word detail:(NSString *)detail

ios - cannot assign to 'self' outside of a method in the init family,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!