2016-01-23 35 views
1
var categories: NSSet = NSSet(object: firstCategory) 
let types: UIUserNotificationType = UIUserNotificationType.Badge | UIUserNotificationType.Alert 

没有工作,并说二进制运算符'|'不能适用于两个“UIUserNotificationType”操作数UIUserNotificationSettings不能工作

var categories: NSSet = NSSet(object: firstCategory) 
var mySettings = UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge], categories: categories) 

也没有工作,并表示无法指定类型的不可变的表达“UIUserNotificationSettings.Type

回答

0

这应该工作:

var categories = Set(arrayLiteral: firstCategory) 
var mySettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge], categories: categories) 

你有太多=在你的第二行。此外,您需要使用Set而不是NSSet

+0

哇,非常感谢,我写错误':'为'='...... – postman99

+0

有时Swift错误有误导性。 – Mark

0

尝试设置这样的:

var categories: Set = Set(object: firstCategory) 
    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert, UIUserNotificationType.Badge categories: categories))