关于error:Cannot assign to 'self' outside of a method in the init family
2016-03-17 15:54
597 查看
问题:
有时候我们重写父类的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]; }
相关文章推荐
- c++ 引用
- docker 创建镜像
- picasso-强大的Android图片下载缓存库
- bash属组,特殊权限与facl,ulimit
- Ubuntu
- Spring+SpringMVC+mybatis+Jquery easyUI框架整合
- cucumber学习索引
- 19. Remove Nth Node From End of List
- VMwareTools安装及使用
- BMP格式、读写
- HTML5新控件 - 颜色选择器
- cart决策树
- nginx, tomcat 集群
- DataTable的数据去重
- 转:what is TWO_TASK
- MD5加密
- 虚拟机ubuntu全屏显示设置
- java 不复制字符串前提下替换字符串中的空格算法实现O(n)
- 在Eclipse的Debug页签中设置虚拟机参数
- 排序算法之Bubble sorts and variants