-(NSDate *)beginningOfDay:(NSDate *)date
{
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSMonthCalend
Swift3 Using *XCode8
Apple is removing the NS
from the class name so that NSDate
can be swapped out to Date
. You may get a compiler warning if you try to cast them saying they will always fail, but they work fine when you run them in the playground.
I replaced my generated NSDate
in core data model with Date
and they still work.
extension Date {
func startTime() -> Date {
return Calendar.current.startOfDay(for: self)
}
func endTime() -> Date {
var components = DateComponents()
components.day = 1
components.second = -1
return Calendar.current.date(byAdding: components, to: startTime())!
}
}