Call methods from Swift initializer -


let's have following class in swift (which has obvious problems)

class myclass {     let myproperty: string      init() {         super.init()         self.setupmyproperty()     }      func setupmyproperty() {         myproperty = "x"     } } 

this overly simplified i'm trying delegate initialization of myproperty setupmyproperty() method. it's pattern use break down different parts of setup of class.

but of course, can't call self until super initializer has run, , can't run super initializer until properties have been set, i'm in catch 22. on top of since setupmyproperty() isn't considered initializer, won't able assign myproperty anyway.

can tell me how implement pattern in swift?

declare implicitly unwrapped optional

class myclass : nsobject {     var myproperty: string!      init() {         super.init()         self.setupmyproperty()     }      func setupmyproperty() {         self.myproperty = "x"     } } 

page 499 of "the swift programming language" manual


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

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