Working with Swift LocationManager
I started out creating location managers on each controller and then I read this. As there should ever only be one instance of the LocationManager, a singleton is definitely the right way to go.
Swift 3 Singleton
import CoreLocation class LocationManager: CLLocationManager { var isUpdatingLocation = false static let shared = LocationManager() override func startUpdatingLocation() { super.startUpdatingLocation() isUpdatingLocation = true } override func stopUpdatingLocation() { super.stopUpdatingLocation() isUpdatingLocation = false } }
Usage
if LocationManager.shared.isUpdatingLocation { print("Is currently updating location.") } else { print("Location updates have stopped.") }












