calling a convenience initializer from subclass

Hi


I know a convenience intializer should eventually call a designated initilizer in the same class. But is there a way to use superclass's convenience initilizer in a subclass? I inherited a subclass from class XMLParser, which is a foundation class, I do not know how to override/custom the superclass's initilizer.

Thanks anyway.

You're probably better off going directly to the official documentation:


developer.apple.com/library/prerelease/content/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html


starting at the heading "Class Inheritance and Initialization".The answer depends on whether you're providing any designated or convenience initializers in your subclass, and whether you want to use a designated or convenience initializer in the superclass. You pretty much have to work through the rules for initializer inheritance to find out what you have available in your subclass.

I found a way to do the job. If I want to inherit superclass's convenience initializer in a subclass, I have to follow the rule 1 and 2 as been introduced in heading "Automatic initializer inheritence", in the swift programming manual. More specially,


“Rule 1

If your subclass doesn’t define any designated initializers, it automatically inherits all of its superclass designated initializers.



Rule 2

If your subclass provides an implementation of all of its superclass designated initializers—either by inheriting them as per rule 1, or by providing a custom implementation as part of its definition—then it automatically inherits all of the superclass convenience initializers.”



Excerpt From: Apple Inc. “The Swift Programming Language (Swift 3).” iBooks

calling a convenience initializer from subclass
 
 
Q