2016-03-23 14 views
0

Gestern habe ich den neuen Xcode 7.3 installiert und mein Problem hat begonnen.Syntaxfehler nach Xcode 7.3 Update

Ich muss viele Änderungen vornehmen, die mit swift 3 kommt. viele Änderungen habe ich mit der "Autokorrektur" von Xcode gelöst.

Aber es gibt zwei Dinge, die nicht automatisch lösen können:

Problem 1 enter image description here

Problem 2

for (var x = 1; x < self.ACData.count; x ++) { 

Aber ich sollte dies tun:

enter image description here

Wenn ich die Korrektur anwenden ich diese:

for (x in 2 ..< self.ACData.count) { 

und das macht mir einen Syntaxfehler. Kann mir bitte jemand helfen? :)

UPDATE

let app:UIApplication = UIApplication.sharedApplication() 
    for oneEvent in app.scheduledLocalNotifications! { 
    let notification: AnyObject = oneEvent 
    let userInfoCurrent = notification.userInfo as! [NSObject: AnyObject] 
    if userInfoCurrent["UUID"] == nil { 
     app.cancelLocalNotification(notification as! UILocalNotification) 
    } 
} 

Antwort

0

Problem 1:

Sie nicht niedergeschlagen, nicht erforderlich. Sie können eine Zeichenfolge für die NSObject, geben Sie so einfach schreiben:

let userInfoCurrent = notification.userInfo! 

Problem 2:

die Klammern entfernen. Das ist wirklich alles, was Sie tun müssen, um es zu beheben, nicht schreiben:

for (x in 2 ..< self.ACData.count) 

Das ist nicht die richtige rasche Art und Weise ist, sollte es sein:

for x in 2 ..< self.ACData.count { 

Update:

Basierend auf dem Code oben gezeigt ich die beste Art und Weise denken, dies zu tun ist:

let app:UIApplication = UIApplication.sharedApplication() 
for oneEvent in app.scheduledLocalNotifications! { 
    let notification: AnyObject = oneEvent 
    guard let userInfoCurrent = notification.userInfo, 
      let uuid = userInfoCurrent["UUID"] else { 
      app.cancelLocalNotification(notification as! UILocalNotification)   
      return //or continue, don't know if you want to keep looping after this 
    } 
    // Do something with UUID if it's not necessary you can update the code as follows: 
    // guard let userInfoCurrent = notification.userInfo where userInfoCurrent["UUID"] != nil else { 
} 

ich hoffe, das funktioniert

+0

, wenn ich für das Problem Ihre Lösung verwende 1 bekomme ich die Fehlermeldung: 'mehrdeutige Verwendung von‚userInfo''. Problem 2 kann wie dein Weg gelöst werden :) – Stack108

+0

Hmm komisch. Was ist mit 'let userInfoCurrent = notification.userInfo as! [NSObject: AnyObject] ' –

+0

selbe Fehler:/:( – Stack108

0

Problem 1:

scheduledLocalNotifications ist eindeutig als [UILocalNotification]? erklärt.
Die Anmerkung zu AnyObject ist sehr schlecht.

Grundsätzlich Anmerkungen werden nicht benötigt, da der Compiler den Typ

let app = UIApplication.sharedApplication() 
if let localNotifications = app.scheduledLocalNotifications { 
    for notification in localNotifications { 
     let userInfoCurrent = notification.userInfo as! [String: AnyObject] 
     if userInfoCurrent["UUID"] == nil { 
     app.cancelLocalNotification(notification) 
     } 
    } 
} 

oder noch einfacher

let app = UIApplication.sharedApplication() 
if let localNotifications = app.scheduledLocalNotifications { 
    for notification in localNotifications { 
    if notification.userInfo?["UUID"] == nil { 
     app.cancelLocalNotification(notification) 
    } 
    } 
} 

Problem 2 entnehmen kann:

Im Gegensatz zu Objective-C in Klammern if/for/while Bedingungen sind nicht erforderlich in Swift und sogar könnte Probleme wie in Ihrem Fall verursachen.

Entfernen Sie einfach die Klammern

for x in 2 ..< self.ACData.count { 
+0

thx - das funktioniert! – Stack108

Verwandte Themen