将NSCalendarUnit转换为Swift2

时间:2016-01-20 19:25:52

标签: ios swift uilocalnotification nscalendar

我有下一个代码:

var notification = UILocalNotification()
    notification.alertBody = "Message" // text that will be displayed in the notification
    notification.fireDate = NSDate()  // right now (when notification will be fired)
    notification.soundName = UILocalNotificationDefaultSoundName // play default sound

    let calendar = NSCalendar.currentCalendar()
    let components = calendar.components([.Minute], fromDate: NSDate())

    notification.repeatInterval = NSCalendarUnit.CalendarUnitHour // this line defines the interval at which the notification will be repeated
    UIApplication.sharedApplication().scheduleLocalNotification(notification)

但它已被弃用。搜索了很多,但无法将其转换为Swift2。任何人都可以帮我解决问题:

notification.repeatInterval = NSCalendarUnit.CalendarUnitHour

1 个答案:

答案 0 :(得分:0)

Swift 2中的枚举比Objective-C好得多。

尝试下一行:

notification.repeatInterval = NSCalendarUnit.Hour

应该有效。