osx - swift subclass init tangle -


i have base class 2 init methods - 1 designated list of parameters, other convenience init obtains parameter values nsdictionary (which used serialise objects). until attempt create subclass - convenience init produces error if attempt call matching super.init(...) , demands call designated init of subclass. superclass contains keys used extract parameter values , don't want duplicate code or have public key values.

i set dummy values , use separate loadfromdict() method (which can overridden) seems awkward. there way?

the error seeing normal, if follows rules initialization in swift. convenience init must call init in same class. other init convenience, or designated. @ point though designated init needs called in subclass before calls super class. swift enforces designated init can call super class init. swift language reference

to simplify relationships between designated , convenience initializers, swift applies following 3 rules delegation calls between initializers:

rule 1

a designated initializer must call designated initializer immediate superclass.

rule 2

a convenience initializer must call initializer same class.

rule 3

a convenience initializer must call designated initializer.

a simple way remember is:

designated initializers must delegate up.

convenience initializers must delegate across.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -