Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does @IBInspectable get set?

Tags:

ios

swift

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
}
like image 604
Marcelo Avatar asked Jun 22 '14 05:06

Marcelo


1 Answers

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
} 
like image 59
Grimxn Avatar answered Nov 09 '22 01:11

Grimxn