Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No '+' candidates produce the expected contextual result type 'NSNumber?' Swift 3

Tags:

xcode8

swift3

On Xcode 8 and Swift 3 is comes an error by + i have try it anything but come to no result. Here the code :

static func addNotificationInterval(title: String, body: String,

indentifier: String, interval: Double) {

    let content = UNMutableNotificationContent()
    content.title = NSString.localizedUserNotificationString(forKey: title, arguments: nil)
    content.body = NSString.localizedUserNotificationString(forKey: body, arguments: nil)
    content.sound = UNNotificationSound.default()
    content.badge = UIApplication.shared.applicationIconBadgeNumber + 1; content.categoryIdentifier = "com.elonchan.localNotification"

    let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: interval, repeats: true)
    let request = UNNotificationRequest.init(identifier: indentifier, content: content, trigger: trigger)
    let center = UNUserNotificationCenter.current()

    center.add(request)

    print("SetNotifiInterval")

}

Error comes here by the + :

content.badge = UIApplication.shared.applicationIconBadgeNumber + 1; content.categoryIdentifier = "com.elonchan.localNotification"

Error Type:

No '+' candidates produce the expected contextual result type 'NSNumber?'

like image 991
Mike West Avatar asked Sep 26 '16 21:09

Mike West


1 Answers

Check the latest reference of UNMutableNotificationContent:

var badge: NSNumber?

The number to apply to the app’s icon.

In Swift 3, many implicit type conversions, like Int to NSNumber, are removed. You need to explicitly cast the types between them.

content.badge = (UIApplication.shared.applicationIconBadgeNumber + 1) as NSNumber; ...
like image 197
OOPer Avatar answered Oct 01 '22 07:10

OOPer