High speed getter without getter

How do you implement a setter without getter in Swift? I need to call the method when the value is set:

var selectedIndex : Int{
set{
    selectItemAtIndex(newValue)
}
}

but in Swift you need to use both getter and setter, not just one.

+4
source share
1 answer

You can use the observer property didSet. This will be called immediately after setting the value.

var selectedIndex: Int {
  didSet {
    selectItemAtIndex(selectedIndex)
  }
}
+16
source

Source: https://habr.com/ru/post/1544698/


All Articles