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

Popular posts from this blog

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -