Date NSDateComponents returns NSTaggedDate (inner class) instead of NSDate

NSCalendar *gCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *oldDate = [NSDate date]; // Or however you get it.
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay;
NSDateComponents *comps = [gCalendar components:unitFlags fromDate:oldDate];
comps.hour   = 23;
comps.minute = 59;
comps.second = 59;
comps.calendar = gCalendar;
NSDate *newDate = [gCalendar dateFromComponents:comps];

When I run the above snippet, the variable newDate is of type __NSTaggedDate. This ultimately causes problems because __NSTaggedDate cannot subsequently be serialized by JSON.

I am trying to create an NSDate that has the last second time of today.

I am on Xcode 6.4, and iOS 8.4 is running on my phone. This happened both on the simulator and on the iPhone6.

+4
source share

Source: https://habr.com/ru/post/1598416/


All Articles