关于error:Cannot assign to 'self' outside of a method in the init family
2016-05-17 10:00
721 查看
有时候我们重写父类的init方法时不注意将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;
出错代码:- (id) Myinit{
self = [super init];
……
}
解决方法:- (id) initWithMy
{
self = [super init];
}
原因:只能在init方法中给self赋值,Xcode判断是否为init方法规则:方法返回id,并且名字以init+大写字母开头+其他 为准则。例如:- (id) initWithXXX;
出错代码:- (id) Myinit{
self = [super init];
……
}
解决方法:- (id) initWithMy
{
self = [super init];
}
相关文章推荐
- iOS开发之详谈属性设置readwrite、readonly、retain、copy、assign、nonatomic
- @property 详细剖析
- ios property探秘
- 认识retain copy assign strong weak 的区别
- copy, retain, assign , readonly , readwrite,strong,weak,nonatomic整理
- 属性(一):assign,copy,retain...
- retain,copy,assign及autorelease
- 关于IOS delegate的weak和assign 探讨
- iOS开发-retain/assign/strong/weak/copy/mutablecopy/autorelease区别
- iOS内存管理之@property属性详解
- @property属性修饰符
- @property常用参数
- assign,copy,retain的解释
- [7]姥爷幽默谈Objective-C-属性@property,类别Category
- property参数strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- $this->assign(); 与 $this->display(); PHP
- IOS atomic与nonatomic,assign,copy与retain的定义和区别
- iOS中assign、copy 、retain等关键字的含义(转载)
- C++中assign的用法
- cannot assign to 'self' outside of a method in the init family