CeraMo69 CeraMo69 - 1 year ago 82
Swift Question

When/How - Outlet -> didSet

I'm wondering, when/how does the didSet on an outlet actually trigger?

For example :

@IBOutlet weak var modifyButton: UIButton! {
didSet {
modifyButton.layer.cornerRadius = 9

Answer Source

Outlet properties initialized as nil when class just initialized. They will have values later, when objects will be initialized from nib. First step, when you can be sure that all properly configured outlet properties have nonnil values is viewDidLoad. So, didSet observer on this properties will be called just before viewDidLoad. Because all of this you need to be careful with outlet properties: for example you will receive nil if you will try access them in prepareForSegue method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download