没有'+'候选人产生预期的上下文结果类型'NSNumber?'斯威夫特3

时间:2016-09-26 21:51:35

标签: swift3 xcode8

在Xcode 8和Swift 3上出现错误+我已尝试过任何事情,但没有结果。 代码如下:

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")

}

错误来自+:

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

错误类型:

没有'+'候选人产生预期的上下文结果类型'NSNumber?'

1 个答案:

答案 0 :(得分:9)

检查the latest reference of UNMutableNotificationContent

  

var badge: NSNumber?

     

应用于应用程序图标的数字。

在Swift 3中,删除了许多隐式类型转换,例如IntNSNumber。您需要在它们之间明确地转换类型。

content.badge = (UIApplication.shared.applicationIconBadgeNumber + 1) as NSNumber; ...