I am checking if location services are enabled for the app. Looking at the code below, why can I not use "!manager.locationServicesEnabled()" since locationManager is of type CLLocationManager?

override func viewDidLoad() {

    enableLocationServices(manager: locationManager)


func enableLocationServices(manager: CLLocationManager) {

    manager.delegate = self

    if !CLLocationManager.locationServicesEnabled() {

1 Answers

rmaddy On Best Solutions

Assuming you are asking why you must use CLLocationManager.locationServicesEnabled() and not manager.locationServicesEnabled() then the answer is simply that locationServicesEnabled is a type method and must be called on the class, not an instance of the class.

When looking at the documentation for a method or property, if it starts with class or static then you call it on the class, struct, or enum directly. If it doesn't start with class or static, then you call it on a specific instance of the class, struct, or enum.