Check out example codes for "setter must be with getter swift". It will help you in understanding the concepts better.
Code Example 1
// Sure. You can just return a nil and make the type optional:
var color: MyColorEnum? {
get { return nil }
set {
switch newValue! {
case .Blue:
view.backgroundColor = UIColor.blueColor()
case .Red:
view.backgroundColor = UIColor.redColor()
}
}
}
// Alternatively, you may use didSet to avoid the issue all together:
var color: MyColorEnum! {
didSet {
switch color {
case .Blue:
view.backgroundColor = UIColor.blueColor()
case .Red:
view.backgroundColor = UIColor.redColor()
}
}
}
Learn ReactJs, React Native from akashmittal.com