Complete the code to import the framework needed for location services.
import [1]
You need to import CoreLocation to use location services in iOS apps.
Complete the code to declare a location manager variable.
var locationManager = [1]()The CLLocationManager class manages location updates.
Fix the error in the code to request location permission from the user.
locationManager.[1]()To ask the user for permission to access location only when the app is in use, use requestWhenInUseAuthorization().
Fill both blanks to set the delegate and desired accuracy for the location manager.
locationManager.[1] = self locationManager.[2] = kCLLocationAccuracyBest
You set the delegate to receive location updates and set desiredAccuracy to specify how accurate the location should be.
Fill all three blanks to start location updates and handle authorization status.
if CLLocationManager.authorizationStatus() == .authorizedWhenInUse { locationManager.[1]() } else { locationManager.[2]() } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { guard let location = locations.[3] else { return } print("User location: \(location.coordinate.latitude), \(location.coordinate.longitude)") }
If authorized, start updating location with startUpdatingLocation(). Otherwise, request permission with requestWhenInUseAuthorization(). In the delegate method, get the first location from the array.