zoukankan      html  css  js  c++  java
  • 关于Cannot assign to 'self' outside of a method in the init family解决方法

          有时候我们重写父类的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];

    }

    转载自http://www.aichengxu.com/view/34741

    纸上得来终觉浅,绝知此事要躬行
  • 相关阅读:
    P1071 潜伏者
    P2199 最后的迷宫
    推荐
    T150191 求和
    T150189 养猪
    P1106 删数问题
    NOIP 2018 提高组初赛试题胡谈
    结题报告
    博客迁移公告
    简单实用算法——用队列实现栈
  • 原文地址:https://www.cnblogs.com/asheng/p/4141197.html
Copyright © 2011-2022 走看看