Skip to main content

Posts

Showing posts from November, 2019

Execute a method when a variable value changes in Swift

This post is about how to execute a function when a variable value changes.
Instead of key-value observation, simply use a property observer for the variable.  For e.g: Whenever the value of variable named allSlot changes, the two lines will execute which are written in the didSet method. privatevarallSlot: [String] = [] { didSet { slotTableView?.reloadData() enableRightBarButton() } }
Property observers: https://docs.swift.org/swift-book/LanguageGuide/Properties.html#//apple_ref/doc/uid/TP40014097-CH14-ID262