I would like to apply DRY to the lines I'm creating in swift. How can I refactor this code so a closure is called? It resides on a viewcontroller.
var topLineView: UIView = {
let lineView = UIView()
lineView.layer.borderWidth = 1.0
lineView.layer.borderColor = UIColor.lightGray.cgColor
return lineView
}()
var bottomLineView: UIView = {
let lineView = UIView()
lineView.layer.borderWidth = 1.0
lineView.layer.borderColor = UIColor.lightGray.cgColor
return lineView
}()
var centerLineView: UIView = {
let lineView = UIView()
lineView.layer.borderWidth = 1.0
lineView.layer.borderColor = UIColor.lightGray.cgColor
return lineView
}()
I tried creating a variable but that caused an error:
let lineView = {
let lineView = UIView()
lineView.layer.borderWidth = 1.0
lineView.layer.borderColor = UIColor.lightGray.cgColor
return lineView
}
var centerLineView = lineView()
error (Unable to infer closure type etc...)