fkuehne / upnpx

Officially endorsed fork of the discontinued upnpx library by Bruno Keymolen
Other
260 stars 113 forks source link

Designated Initializer invoked a non-designated initializer #58

Open lightbow opened 9 years ago

lightbow commented 9 years ago

When building on Xcode 6.2 with the new upnpx 1.3.2, I get a ton of warnings about designated initializers. Looking at the code, the warnings are justified because subclass-overrides of the designated initializer are indeed calling the non-designated initializer on the superclass, for example BasicServiceParser uses this -(instancetype)initWithUPnPDevice:(BasicUPnPDevice*)upnpdevice{ self = [super init]; even though basicParser.h (the superclass) anoints this -(instancetype)initWithNamespaceSupport:(BOOL)namespaceSupport NS_DESIGNATED_INITIALIZER;

While the changes don't seem to break anything at runtime (yet) because [super init] is indeed redirecting back through the designated initializer with -(instancetype)init { return [self initWithNamespaceSupport:NO]; } the whole point of NS_DESIGNATED_INITIALIZER is to make things safer, and it should be adopted completely or not at all.

Here are the rules from the docs:

To clarify the distinction between designated and designated initializers clear, you can add the NS_DESIGNATED_INITIALIZER macro to any method in the init family, denoting it a designated initializer. Using this macro introduces a few restrictions:

  • The implementation of a designated initializer must chain to a superclass init method (with [super init...]) that is a designated initializer for the superclass.
  • The implementation of a convenience initializer (an initializer not marked as a designated initializer within a class that has at least one initializer marked as a designated initializer) must delegate to another initializer (with [self init...]).
  • If a class provides one or more designated initializers, it must implement all of the designated initializers of its superclass.

This problem exists with both the BasicParser and the SoapAction class hierarchy.