When/How - Outlet -> didSet

孤者浪人 提交于 2019-12-18 18:23:49

问题


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
    }
}

回答1:


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



来源:https://stackoverflow.com/questions/38197785/when-how-outlet-didset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!