0
0
iOS Swiftmobile~10 mins

Location services (Core Location) in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the framework needed for location services.

iOS Swift
import [1]
Drag options to blanks, or click blank then click option'
AUIKit
BMapKit
CCoreLocation
DFoundation
Attempts:
3 left
💡 Hint
Common Mistakes
Importing UIKit instead of CoreLocation
Forgetting to import any location framework
2fill in blank
medium

Complete the code to declare a location manager variable.

iOS Swift
var locationManager = [1]()
Drag options to blanks, or click blank then click option'
ACLLocationManager
BLocationManager
CCLLocation
DLocationService
Attempts:
3 left
💡 Hint
Common Mistakes
Using CLLocation instead of CLLocationManager
Using a non-existent class like LocationManager
3fill in blank
hard

Fix the error in the code to request location permission from the user.

iOS Swift
locationManager.[1]()
Drag options to blanks, or click blank then click option'
ArequestWhenInUseAuthorization
BstartUpdatingLocation
CrequestAlwaysAuthorization
DenableLocationServices
Attempts:
3 left
💡 Hint
Common Mistakes
Calling startUpdatingLocation before requesting permission
Using a non-existent method like enableLocationServices
4fill in blank
hard

Fill both blanks to set the delegate and desired accuracy for the location manager.

iOS Swift
locationManager.[1] = self
locationManager.[2] = kCLLocationAccuracyBest
Drag options to blanks, or click blank then click option'
Adelegate
BdesiredAccuracy
ClocationDelegate
Daccuracy
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names like locationDelegate or accuracy
Not setting the delegate before starting updates
5fill in blank
hard

Fill all three blanks to start location updates and handle authorization status.

iOS Swift
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)")
}
Drag options to blanks, or click blank then click option'
AstartUpdatingLocation
BrequestWhenInUseAuthorization
Clast
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Calling requestWhenInUseAuthorization after starting updates
Using last instead of first to get the location
Not checking authorization status before starting updates