2017-01-02 2 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 { ...