Saturday, 13 October 2018

Is there a tangible benefit to using "self" outside of closures?

I have noticed a few people in the industry will use the self keyword even when not explicitly required (i.e. outside of closures).

Example:

import UIKit
import MapView
import CoreLocation

class viewController: UIViewController, MKMapViewDelegate, CLLocationDelegate {

    let mapView = MKMapView()
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.mapView.delegate = self
        self.mapView.showsUserLocation = true

        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    }
}

Is there a tangible benefit to this, runtime-wise? Or is this purely a stylistic choice?



from Is there a tangible benefit to using "self" outside of closures?

No comments:

Post a Comment