Marcelo
Marcelo

Reputation: 1196

When does @IBInspectable get set?

I have a few properties set as @IBInspectable, so I can edit them in the Interface Builder, but during runtime when are those properties set?

I tried using them during the init but they were not set yet.

This is what I am trying to do. But I can't even move the Timer Init to the TimerView Init because the @IBInspectable vars are not set by the time the init is called.

class TimerView {
    var timer:Timer? = Timer(timeInterval: time1, alertTimeInterval: time2)
    @IBInspectable var time1: Double = 0
    @IBInspectable var time: Double = 0
}

Upvotes: 17

Views: 2929

Answers (1)

Grimxn
Grimxn

Reputation: 22487

Like anything set in IB, it will be set when the xib file is loaded. You want to set your timer in awakeFromNib()

override func awakeFromNib() {
    super.awakeFromNib()
    timer = //IBInspectable elements now set
} 

Upvotes: 28

Related Questions