Consider this example of configuring MKMapView
's map type. Should it be done in viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
mapView.mapType = MKMapType.Hybrid
}
or in the var's didSet
?
@IBOutlet weak var mapView: MKMapView! {
didSet {
mapView.mapType = MKMapType.Hybrid
}
}
Both work, what's the Swift preferred way?
They each have a different use.
If you want the mapType
set every time the property is set, use didSet
.
If you only want the mapType
set once when the view is loaded, use viewDidLoad
.
Given what you are doing I would say that didSet
is the more correct choice here.
BTW - this has nothing to do with "the Swift preferred way". The same logic applies regardless of language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With