首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将NSCalendarUnit转换为Swift2

将NSCalendarUnit转换为Swift2
EN

Stack Overflow用户
提问于 2016-01-21 03:25:52
回答 1查看 43关注 0票数 0

我有下面的代码:

代码语言:javascript
复制
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。有人能帮我解决这个问题吗:

代码语言:javascript
复制
notification.repeatInterval = NSCalendarUnit.CalendarUnitHour
EN

回答 1

Stack Overflow用户

发布于 2016-01-21 03:29:02

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

尝试下一行:

代码语言:javascript
复制
notification.repeatInterval = NSCalendarUnit.Hour

它应该是有效的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34908764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档