I am cleaning up the warnings in an app and I got this warning twice
Method override for the designated initializer of the superclass '-init' not found
for this line of code
@implementation AFNetworkReachabilityManager
and this line
@implementation AFURLConnectionOperation
I am fairly new to objective-c and googled this warning and just didn't understand the solutions
My question is how do I get rid of these warnings?
From Apple forums
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.
In your .h
files:
@interface MyClass : NSObject
- (instancetype)init NS_UNAVAILABLE;
@end
In .m
files:
@interface MyClass ()
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
@implementation MyClass
- (instancetype)init { @throw nil; }
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With