SwiftUI force-unwrap
Solution 1:
You can simply provide a default if locations.first!
fails:
init() {
self.locations = ChurchLocationsDataService.locations
// If locations.first fails, you can simply use some default
let firstLocation = ChurchLocationsDataService.locations.first ?? CLLocation(latitude: 0, longitude: 0)
self.mapLocation = firstLocation
self.updateMapRegion(location: firstLocation)
}
You can't use the guard
statements and return because the init()
requires that everything be initialized. Failing in a guard
means that isn't the case.