关于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”这个错误是基于初始化方法

名的编写错误导致的。

原因在于:

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

出错代码:- (instancetype) Myinit{

 self = [super init];

 ……

}

解决方法:- (instancetype) initWithMy

{

 self = [super init];

}