2017-01-02 9 views
-1

konvertiert meine Syntax Swift 3. Als ich das tat, habe ich den Fehler mit diesem CodeMehrdeutige Bezug auf Mitglieder Index 'in Swift 3 Fehler

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

fügen Sie bitte die volle Fehlermeldung und die Zeile, wo sie auftritt – mlidal

Antwort

0

Der Wert des Parameters change ist Any, kann der Compiler nicht folgern, dass es Int sein soll. Sie müssen den Typ entsprechend umwandeln.

Die zuverlässigste Lösung ist alle Werte optional binden und verwenden Sie die entsprechende Eigenschaft NSKeyValueChangeKey:

if let path = keyPath, path == "animatingTab" 
    let new = change?[.newKey] as? Int, new == 2 { ... 
Verwandte Themen