对成员'下标'Swift 3的模糊引用

时间:2016-10-02 15:14:03

标签: swift3

更新到Swift 3后很多地方我收到此错误我改变了地方?而且!但是出现了另一个错误(Type [String:AnyObject]?没有下标成员)

  func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutableRawPointer) {
        if !didFindMyLocation {
            let myLocation: CLLocation = change? [NSKeyValueChangeNewKey] as! CLLocation //Ambiguous reference to member 'subscript'
            viewMap.camera = GMSCameraPosition.camera(withTarget: myLocation.coordinate, zoom: 10.0)
            viewMap.settings.myLocationButton = true

            didFindMyLocation = true
        }
    }

1 个答案:

答案 0 :(得分:2)

如果您已添加override,您将获得第一个提示,即方法不会覆盖其超类中的任何方法。

签名已更改为

func observeValue(forKeyPath keyPath: String?, 
                           of object: Any?, 
                              change: [NSKeyValueChangeKey : Any]?, 
                             context: UnsafeMutableRawPointer?)