嗨,我正在尝试修复这个功能,它在swift 3之前是完全正常的,有人知道变化是什么吗?

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    if !didFindMyLocation {
        let myLocation: CLLocation = change?[NSKeyValueChangeKey] as! CLLocation //Getting an error here Cannot convert value of type '(NSKeyValueChangeKey).Type' (aka 'NSKeyValueChangeKey.Type') to expected argument type 'DictionaryIndex<_, _>'
        viewMap.camera = GMSCameraPosition.camera(withTarget: myLocation.coordinate, zoom: 10.0)
        viewMap.settings.myLocationButton = true

        didFindMyLocation = false
    }

}

最佳答案

您应该提供如下适当的密钥:

let myLocation: CLLocation = change?[NSKeyValueChangeKey.newKey] as! CLLocation

09-16 21:35