在Swift 3中没有更多上下文的表达式是模糊的

Geo*_*e B 3 ios swift3 usernotifications

我正在尝试学习Swift,并正在阅读有关推送通知的教程.

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge , .Sound], categories: nil)
Run Code Online (Sandbox Code Playgroud)

给我错误

"没有更多的上下文,表达的类型是模糊的".

我直接从教程中复制/粘贴了这一行,并在StackOverFlow上找到了相同的行.

我究竟做错了什么?
我正在使用Xcode 8.

rma*_*ddy 11

查看文档UIUserNotificationSettings.它的签名在Swift 3中已经改变,因为它具有类型的值.

你需要:

let settings = UIUserNotificationSettings(types: [.alert, .badge , .sound], categories: nil)
Run Code Online (Sandbox Code Playgroud)

当然,如果您只支持iOS 10及更高版本,那么您根本不应该使用UIUserNotificationSettings它,因为它现在已被弃用.请UNNotificationSettings改用.但是,如果您仍然支持iOS 9或更早版本,那么UIUserNotificationSettings只要您更改为更新的语法,就可以使用.