zoukankan      html  css  js  c++  java
  • Cannot assign to 'self' outside of a method in the init family

    今天在重写父类的init方法时报错如下:

    error:Cannot assign to 'self' outside of a method in the init family

    这种问题以前从来没有遇到过呀。。。当然以前我也从来重写过父类的init方法啦。。。嘿嘿。。。。

    最后发现问题如下:

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

    不注意将init后面的第一个字母写成了小写,在这个方法里面又调用父类的初始化方法(self = [super init];)时会报错

    改成了以下就好了:

    #pragma mark - init
    
    + (instancetype)userInfoModifyFillViewControllerWithModifyType:(UserInfoModifyType)type {
        
        return [[self alloc]initWithPersonInfoModifyTypeModifyType:type];
    }
    
    - (instancetype)initWithPersonInfoModifyTypeModifyType:(UserInfoModifyType)type {
        
        if (self = [super init]) {
            _modifyType = type;
        }
        return self;
    }

    记录一下,小心犯错哟!!

     
  • 相关阅读:
    Servlet
    反射
    Python之装饰器
    app——升级测试点
    Python之基本运算符
    HTTP常见的几种认证机制
    Shell文件包含
    Shell输入/输出重定向
    Shell函数
    Shell循环语句
  • 原文地址:https://www.cnblogs.com/pengsi/p/6137488.html
Copyright © 2011-2022 走看看