Problem with Swift 2.1 and UIUserNotificationSettings

I'm new to app development and have inherited a project which I am currently updating to Swift 2.1.

I've cleaned up all compile errors except this last one, and need some help. The section of code I'm having problems with is as follows:


if application.respondsToSelector("registerUserNotificationSettings:") {


let testAction = UIMutableUserNotificationAction()

testAction.identifier = "TEST_ACTION"

testAction.title = "Reply"

testAction.activationMode = .Background

testAction.authenticationRequired = false

testAction.destructive = false

let category = UIMutableUserNotificationCategory()

category.identifier = "CATEGORY_ID"

category.setActions([testAction], forContext: .Default)

category.setActions([testAction], forContext: .Minimal)

let categories = NSSet(object: category) as! Set<UIUserNotificationCategory>

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)

application.registerUserNotificationSettings(settings)

}


The line...

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)

diplays this error: cannot convert value of type ‘Set<UIUserNotificationCategory>’ to expected argument type ‘Set<UIUserNotificationCategory>?’


And the line...

let categories = NSSet(object: category) as! Set<UIUserNotificationCategory>

displays the warning: Cast from ‘NSSet’ to unrelated type ‘Set<UIUserNotificationCategory>’ always fails


Using Xcode version 7.1 (7B91b)

Any help solving this problem with me would be greatly appreciated!!!

I have tried your code with Xcode version 7.1 (7B91b), and it compiles without any problem.

(I recommend you to use availability checking feature of Swift rather than respondsToSelector:

        if #available(iOS 8.0, *) {

but that's another problem.)


Do you still find your issue after Clean & Build?

OOPer thank you for your reply!

After reading you response I had idea of what might be happening, and my assumption was correct. For whatever reason, my project had a wrapper for Set. Once I modified the proejct and eliminated this wrapper everything compiles.


I will take your advice and look into the availability checking feature.


Thanks!

Problem with Swift 2.1 and UIUserNotificationSettings
 
 
Q