Swift 错误 EXC_BAD_INSTRUCTION

Swift error EXC_BAD_INSTRUCTION

请给我这个代码。我是 Swift 的新手(今天才开始)。这里有什么问题?我尝试搜索堆栈,但只找到 Objective-C 个解决方案。

class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()

@IBOutlet weak var mapView: MKMapView!

override func viewDidLoad() {
    super.viewDidLoad()
    locationManager.delegate = self

    if (CLLocationManager.locationServicesEnabled()) {
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
    }
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    let location = locations.last! as CLLocation

    let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

    mapView.setRegion(region, animated: true)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

您可能忘记在代码中将情节提要中的地图视图挂接到 mapView 出口。