2016-01-23 33 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))