相关疑难解决方法(0)

Swift 2.0 - 二进制运算符"|" 不能应用于两个UIUserNotificationType操作数

我试图以这种方式注册本地通知的应用程序:

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.请帮我.

ios swift swift2

191
推荐指数
3
解决办法
5万
查看次数

如何将NSDate对象设置为午夜?

我有一个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 */),因此您只能使用下列其中一个准确度:

  1. 小时
  2. 分钟

有没有办法同时设置小时,分钟和秒并保留日期(日/月/年)?

datetime nsdate nscalendar ios swift

50
推荐指数
5
解决办法
3万
查看次数

标签 统计

ios ×2

swift ×2

datetime ×1

nscalendar ×1

nsdate ×1

swift2 ×1