Skip to content

Commit 401de7e

Browse files
committed
Update for Swift 3
1 parent 55c54b2 commit 401de7e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

CoreLocationCLI/main.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
3131
print("headingAvailable: \(CLLocationManager.headingAvailable())")
3232
print("regionMonitoringAvailable for CLRegion: \(CLLocationManager.isMonitoringAvailable(for: CLRegion.self))")
3333
}
34-
let _ = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: #selector(self.timeout), userInfo: nil, repeats: false)
34+
let _ = Timer.scheduledTimer(timeInterval: 10.0, target: self, selector: #selector(self.timeout), userInfo: nil, repeats: false)
3535
self.locationManager.startUpdatingLocation()
3636
}
3737

@@ -42,7 +42,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
4242
}
4343
}
4444

45-
func printFormattedLocation(location: CLLocation, address: String? = nil) {
45+
func printFormattedLocation(_ location: CLLocation, address: String? = nil) {
4646
var output = self.format
4747
output = output.replacingOccurrences(of: "%latitude", with: String(format: "%+.6f", location.coordinate.latitude))
4848
output = output.replacingOccurrences(of: "%longitude", with: String(format: "%+.6f", location.coordinate.longitude))
@@ -62,39 +62,41 @@ class Delegate: NSObject, CLLocationManagerDelegate {
6262

6363
}
6464

65-
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
65+
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
6666
switch status {
67-
case .Authorized:
67+
case .authorizedAlways:
6868
print("Location access authorized.")
69-
case .NotDetermined:
69+
case .notDetermined:
7070
print("Undetermined location access.")
71-
case .Denied:
71+
case .denied:
7272
print("User denied location access. Exiting.")
7373
exit(1)
74-
case .Restricted:
74+
case .restricted:
7575
print("Location access restricted. Exiting.")
7676
exit(1)
77+
default:
78+
break
7779
}
7880
}
7981

80-
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
82+
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
8183
exitAtTimeout = false
82-
let location = locations.first as! CLLocation
84+
let location = locations.first!
8385

8486
if format.range(of: "%address") != nil {
8587
self.locationManager.stopUpdatingLocation()
8688
self.geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in
8789
if let postalAddress = placemarks?.first?.postalAddress {
8890
let formattedAddress = CNPostalAddressFormatter.string(from: postalAddress, style: CNPostalAddressFormatterStyle.mailingAddress)
89-
self.printFormattedLocation(location: location, address: formattedAddress)
91+
self.printFormattedLocation(location, address: formattedAddress)
9092
}
9193
else {
92-
self.printFormattedLocation(location: location, address: "?")
94+
self.printFormattedLocation(location, address: "?")
9395
}
9496
self.locationManager.startUpdatingLocation()
9597
})
9698
} else {
97-
printFormattedLocation(location: location)
99+
printFormattedLocation(location)
98100
}
99101
}
100102

0 commit comments

Comments
 (0)