override - Overriding default value of instance var -
given class obj
,
class obj: nsobject { var x = "x" }
and subclass, obj1
, how change default value of var x
?
simply setting new value make sense, seems error out...
class obj1: obj { var x = "y" }
❗️ cannot override stored property 'x'
define init()
method as:
init () { super.init() x = "y" }
you'll want other initializers in obj1
invoke self.init()
. apple documentation has long discussion on designated initializers , inheritance vis-a-vis initializers.
Comments
Post a Comment