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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -