Lee Lee - 6 months ago 134
Swift Question

Swift 3.0 Syntax change for UIUserNotificationSettings

I am using swift 3.0 and am trying to add badge numbers to my app. I believe the correct way to do this is similar to what is below.

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
UIUserNotificationType.Badge, categories: nil

application.applicationIconBadgeNumber = 5

However, I get an error for using '|' in
block and will also receive the error "Argument labels (forTypes, categories) do not match any of the available overloads" for
if I only have
as the first argument. Did swift 3.0 change the syntax for this statement?


It has been updated in both Swift 2 and Swift 3. This line should fix your issue. Also make sure any other lines with UIUserNotificationType have had their variables switched to lowercase.

let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)