2017-01-02 7 views
-1

は私がやったとき、私はこのコードあいまいな参照が

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

    if keyPath! == "animatingTab" && change!["new"]!.isEqual(NSNumber (value: 2 as Int))// here i got error{ 

     UIView.animate(withDuration: 0.25, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: { 
      self.settingsView.frame.origin = CGPoint(x: LayoutService.width(widthPercentage: 20), y: 0) 
      self.settingsView.setShadows() 
     }, completion: nil) 

    } 
    else if keyPath! == "animatingTab" && !change!["new"]!.isEqual(NSNumber(value: 2 as Int))// here i got error { 

     UIView.animate(withDuration: 0.25, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: { 
      self.settingsView.frame.origin = CGPoint(x: LayoutService.width(widthPercentage: 100), y: 0) 
      self.settingsView.clearShadows() 
     }, completion: nil) 

    } 

    if keyPath! == "currentUser" { 
     self.settingsView.profileView.buildProfileForUser(user: AccountService.sharedInstance.currentUser!) 
    } 
} 
+1

完全なエラーメッセージが表示され、それが発生した行を追加してください。 – mlidal

答えて

0

パラメータchangeの値がAnyあるとエラーを得たスウィフト3に私の構文を変換コンパイラはできませんIntであると推測されます。それに応じてタイプをキャストする必要があります。

最も信頼性の高いソリューションは、オプションのバインドにすべての値であるとNSKeyValueChangeKeyの適切なプロパティを使用します。

if let path = keyPath, path == "animatingTab" 
    let new = change?[.newKey] as? Int, new == 2 { ... 
関連する問題