gpt4 book ai didi

ios - 将 NSCalendarUnit 转换为 Swift2

转载 作者:行者123 更新时间:2023-11-30 13:46:09 25 4
gpt4 key购买 nike

我有下一个代码:

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

最佳答案

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

尝试下一行:

notification.repeatInterval = NSCalendarUnit.Hour

它应该可以工作。

关于ios - 将 NSCalendarUnit 转换为 Swift2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34908764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com