Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we use observer methods to modify IBOutlet properties

Tags:

ios

swift

I have seen code where IBOutlets modify their properties using a didSet like so..

@IBOutlet private weak var tableView: UITableView! {
    didSet {
        tableView.dataSource = self
        tableView.delegate = self
    }
 }

Is this considered good practice, or should we create a configure method in viewDidLoad?

like image 285
Mocha Avatar asked Nov 26 '25 00:11

Mocha


1 Answers

Actually didSet here

outer part 
   didSet { 
     // refresh
  }

makes more sense if the outer var you observe is rapidly changing / real time so you need to react to this change , but for the current case which is the table is set only once from IB inner init using didSet has no bounce over putting the code inside viewDidLoad

like image 84
Sh_Khan Avatar answered Nov 27 '25 14:11

Sh_Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!