ios - How to avoid set method when assign the value in swift? -


in objective-c can use self.foo = xxx call -setfoo: method , use _foo = xxx avoid it.

but how can avoid set when using swift?

i doing this.

// use foo = xxx call set public var foo: int {     set {         fooinside = newvalue         // ...         bar()     }     { return fooinside } } // use fooinside = xxx avoid set private var fooinside = 0 

do have more elegant way? thanks.

i think extension elegant this:

extension int {     mutating func setvalue(value: int,update: bool) {         self = value         if update {          }     } } 

Comments