Hello, I am trying to show my current latitude and longitude, but I keep getting this error:
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
How do I fix it?
import UIKit
import CoreLocation
class ViewController: UIViewController {
@IBOutlet weak var longitude: UILabel!
@IBOutlet weak var latitude: UILabel!
var locManager = CLLocationManager()
var currentLocation: CLLocation!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
locManager.requestWhenInUseAuthorization()
if
locManager.authorizationStatus == .authorizedWhenInUse ||
locManager.authorizationStatus == .authorizedAlways
{
currentLocation = locManager.location
}
longitude.text! = "\(currentLocation.coordinate.longitude)"
latitude.text! = "\(currentLocation.coordinate.latitude)"
}
}