Benr783
Benr783

Reputation: 2890

Intercept setObject functions on class properties in Swift

I have the line var user = BRUser() at the top of my Swift file class BRProfileTableViewCell.
BRUser is a struct with details such as fullName, etc. I set the user value in cellForRowAtIndexPath in my table view controller.

How could I intercept the setUser function to set the label text of the table view cell to the fullName of the user?

Upvotes: 0

Views: 186

Answers (1)

nhgrif
nhgrif

Reputation: 62062

It sounds like you don't need to intercept anything, but rather you need to observe changes in the property, and for that, you want Swift's property observers:

var user: BRUser = BRUser() {
    willSet {
        // do something just before user is set
    }
    didSet {
        // do something just after user is set
    }
}

Upvotes: 1

Related Questions