Advertisement
Guest User

Untitled

a guest
Aug 27th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.69 KB | None | 0 0
  1. class MainViewModel: ObservableObject {
  2.     @ObservedObject var locationManager = LocationManager()
  3.     var cancellable = AnyCancellable {}
  4.  
  5.     init() {
  6.         cancellable = locationManager.$lastLocation.sink { location in
  7.             log("location observer", .notification, location?.coordinate) // prints a real location
  8.             if location != nil { // locationManager.lastLocation != nil
  9.                 self.updateModels { _ in }
  10.             }    
  11.         }
  12.     }
  13.  
  14.     func updateModels(completion: @escaping (String) -> Void) {
  15.         let coordinates: Coordinates = .init(locationManager.lastLocation!.coordinate) // Unexpectedly found nil while unwrapping an Optional value
  16.         ... // some code
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement