So what I wanna do is:
let margin: CGFloat = 10
let width: CGFloat = 100 - margin
// also used self.margin
but here's the error I'm getting:
Instance member 'margin' cannot be used on type 'HistoryViewController'
What should I do?
let margin: CGFloat = 10
var width: CGFloat { return 100 - self.margin }
Or
lazy var width: CGFloat = 100 - self.margin
This is because at instance variable initialization time, the instance doesn't exist yet. Using lazy initialization or a computed property will fix this.
You can do it like this:
first declare the class level variables like this:
let margin: CGFloat = 10
var width = CGFloat()
Then give your width a value inside a function, say viewDidLoad() like this:
override func viewDidLoad() {
super.viewDidLoad()
width = 100 - margin
}
Thank You!
Happy Coding