Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

property observer in swift

struct Person {
    var clothes: String {
        willSet {
            updateUI(msg: "I'm changing from (clothes) to (newValue)")
        }

        didSet {
            updateUI(msg: "I just changed from (oldValue) to (clothes)")
        }
    }
}

func updateUI(msg: String) {
    print(msg)
}

var taylor = Person(clothes: "T-shirts")
taylor.clothes = "short skirts"
Source by www.hackingwithswift.com #
 
PREVIOUS NEXT
Tagged: #property #observer #swift
ADD COMMENT
Topic
Name
9+4 =