关于error:Cannot assign to 'self' outside of a method in the init family
2014-02-25 10:23
337 查看
关于error:Cannot assign to 'self' outside of a method
in the init family
有时候我们重写父类的init方法时不注意将init后面的第一个字母写成了小写,在这个方法里面又调用父类的初始化方法(self = [super init];)时会报错,错误信息如下:error:Cannotassign to 'self' outside of a method in the init family
原因:
只能在init方法中给self赋值,Xcode判断是否为init方法规则:方法返回id,并且名字以init+大写字母开头+其他
为准则。例如:- (id) initWithXXX;
错误示例;
-(id)initwithManagedObjectContext:(NSManagedObjectContext
*)context;
-(id)initwithManagedObjectContext:(NSManagedObjectContext
*)context
{
self = [super
initWithStyle:UITableViewStylePlain];
if (self) {
self.managedObjectContext = context;
}
return
self;
}
相关文章推荐
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to \'self\' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- [ios]关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family