我试图以这种方式注册本地通知的应用程序:
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
Run Code Online (Sandbox Code Playgroud)
在Xcode 7和Swift 2.0中 - 我收到错误Binary Operator "|" cannot be applied to two UIUserNotificationType operands.请帮我.
我有一个NSDate对象,我想将它设置为任意时间(比如半夜),这样我可以使用timeIntervalSince1970的功能一致,而不用担心时间来检索数据时创建的对象.
我尝试使用NSCalendar一些Objective-C方法来修改它的组件,如下所示:
let date: NSDate = NSDate()
let cal: NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
let components: NSDateComponents = cal.components(NSCalendarUnit./* a unit of time */CalendarUnit, fromDate: date)
let newDate: NSDate = cal.dateFromComponents(components)
Run Code Online (Sandbox Code Playgroud)
上述方法的问题在于您只能设置一个时间单位(/* a unit of time */),因此您只能使用下列其中一个准确度:
有没有办法同时设置小时,分钟和秒并保留日期(日/月/年)?