2016-09-23 24 views
0

最近將我的應用程序從以前的版本轉換爲swift 3.可以預料的是,這在我的代碼中導致了很多錯誤。我不知道如何解決下列之一: (在Appdelegate.swift):Error.code在swift 3中不再有效的語法?

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { 
     if error.code == 3010 { 
      print("Push notifications are not supported in the iOS Simulator.\n") 
     } else { 
      print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error) 
     } 
    } 

給出的錯誤是錯誤類型的值沒有任何成員「代碼」。我如何解決這個問題?

回答

3

嘗試在swift2 +鑄造錯誤NSError

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { 
    if (error as NSError).code == 3010 { 
     print("Push notifications are not supported in the iOS Simulator.\n") 
    } else { 
     print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error) 
    } 
} 
0

,該功能在swift3 +命名

optional func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) 

,功能命名

optional func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) 

error變化從NSError的類型Error

the codeNSError的財產