@@ -31,7 +31,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
31
31
print ( " headingAvailable: \( CLLocationManager . headingAvailable ( ) ) " )
32
32
print ( " regionMonitoringAvailable for CLRegion: \( CLLocationManager . isMonitoringAvailable ( for: CLRegion . self) ) " )
33
33
}
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 )
35
35
self . locationManager. startUpdatingLocation ( )
36
36
}
37
37
@@ -42,7 +42,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
42
42
}
43
43
}
44
44
45
- func printFormattedLocation( location: CLLocation , address: String ? = nil ) {
45
+ func printFormattedLocation( _ location: CLLocation , address: String ? = nil ) {
46
46
var output = self . format
47
47
output = output. replacingOccurrences ( of: " %latitude " , with: String ( format: " %+.6f " , location. coordinate. latitude) )
48
48
output = output. replacingOccurrences ( of: " %longitude " , with: String ( format: " %+.6f " , location. coordinate. longitude) )
@@ -62,39 +62,41 @@ class Delegate: NSObject, CLLocationManagerDelegate {
62
62
63
63
}
64
64
65
- func locationManager( manager: CLLocationManager , didChangeAuthorizationStatus status: CLAuthorizationStatus ) {
65
+ func locationManager( _ manager: CLLocationManager , didChangeAuthorization status: CLAuthorizationStatus ) {
66
66
switch status {
67
- case . Authorized :
67
+ case . authorizedAlways :
68
68
print ( " Location access authorized. " )
69
- case . NotDetermined :
69
+ case . notDetermined :
70
70
print ( " Undetermined location access. " )
71
- case . Denied :
71
+ case . denied :
72
72
print ( " User denied location access. Exiting. " )
73
73
exit ( 1 )
74
- case . Restricted :
74
+ case . restricted :
75
75
print ( " Location access restricted. Exiting. " )
76
76
exit ( 1 )
77
+ default :
78
+ break
77
79
}
78
80
}
79
81
80
- func locationManager( manager: CLLocationManager , didUpdateLocations locations: [ AnyObject ] ) {
82
+ func locationManager( _ manager: CLLocationManager , didUpdateLocations locations: [ CLLocation ] ) {
81
83
exitAtTimeout = false
82
- let location = locations. first as! CLLocation
84
+ let location = locations. first!
83
85
84
86
if format. range ( of: " %address " ) != nil {
85
87
self . locationManager. stopUpdatingLocation ( )
86
88
self . geoCoder. reverseGeocodeLocation ( location, completionHandler: { ( placemarks, error) in
87
89
if let postalAddress = placemarks? . first? . postalAddress {
88
90
let formattedAddress = CNPostalAddressFormatter . string ( from: postalAddress, style: CNPostalAddressFormatterStyle . mailingAddress)
89
- self . printFormattedLocation ( location: location , address: formattedAddress)
91
+ self . printFormattedLocation ( location, address: formattedAddress)
90
92
}
91
93
else {
92
- self . printFormattedLocation ( location: location , address: " ? " )
94
+ self . printFormattedLocation ( location, address: " ? " )
93
95
}
94
96
self . locationManager. startUpdatingLocation ( )
95
97
} )
96
98
} else {
97
- printFormattedLocation ( location: location )
99
+ printFormattedLocation ( location)
98
100
}
99
101
}
100
102
0 commit comments