Initialize variable using another variable's initialized value in Swift -


so wanna is:

let margin: cgfloat = 10 let width: cgfloat = 100 - margin // used self.margin 

but here's error i'm getting:

instance member 'margin' cannot used on type 'historyviewcontroller' 

what should do?

let margin: cgfloat = 10 var width: cgfloat { return 100 - self.margin } 

or

lazy var width: cgfloat = 100 - self.margin 

this because @ instance variable initialization time, instance doesn't exist yet. using lazy initialization or computed property fix this.


Comments

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -