Method override for the designated initializer of the superclass '-init' not found
对于这行代码
@implementation AFNetworkReachabilityManager
和这一行
@implementation AFURLConnectionOperation
我相当新的Objective-C和谷歌这个警告,只是不明白的解决方案
我的问题是如何摆脱这些警告?
解决方法
The rules for designated initialisers are complex and I’m going to bounce you to the docs for the general case. CurIoUsly,I’ve found the best explanation of this to be the “Initialization” section of The Swift Programming Language,because the same concepts apply to both Swift and Objective-C.
In your specific case you should override -init and have it fail at runtime. You should also tag it in your header with NS_UNAVAILABLE which will allow the compiler to catch this in the typical case.
The above applies because your class can’t possibly operate without a Model,and thus you can’t reasonably implement -init in any useful way. If you could,you should. For example,if you were creating your own string object,it would make sense for it to implement -init by calling super and then initialising the string to the empty string.
在.h文件中:
@interface MyClass : NSObject - (instancetype)init NS_UNAVAILABLE; @end
在.m文件中:
@interface MyClass () - (instancetype)init NS_DESIGNATED_INITIALIZER; @end @implementation MyClass - (instancetype)init { @throw nil; } @end