-2

I am passing an NSDate through an NSDictionary that is sent as a Push Notification to another user/multiple users. I am trying to take the NSDate that I sent through the Push Notification and convert it back into an NSDate but the object keeps coming up as an __NSCFDictionary and which is obviously what I don't want. I print out what the NSDictionary key "time" looks like and this is what is put out.

"__type" = Date;
    iso = "2015-03-20T22:05:00.000Z";

how do I convert this __NSCFDictionary to an NSDate?

kygcoleman
  • 734
  • 15
  • 25
  • 2
    you have to get the "iso" key to NSString using [yourDict valueForKey:@"iso"] and convert it to NSDate using NSDateFormatter based on your requirement. Did I misunderstand your question ? – Sai Jithendra Mar 20 '15 at 21:27
  • 1
    First you need to learn what an NSDictionary is and how in differs from an NSString. Then you need to study up on how to use NSDateFormatter. – Hot Licks Mar 20 '15 at 21:38
  • @HotLicks I know what those are and how to use them. I just don't understand why my NSDate is being converted to this __NSCFDictionary type of object and not being left as an NSDate – kygcoleman Mar 20 '15 at 21:47
  • 1
    If you're asking how to convert an NSDictionary into an NSDate then you don't know what it is. – Hot Licks Mar 20 '15 at 21:52

1 Answers1

1

Your statements make it pretty clear that you DON'T really know the difference between dictionaries and dates. The data you posted is a dictionary that contains 2 key/value pairs, one of which contains a date string. You need to fetch the value for the "iso" key and use a date formatter to convert it to a date.

NSDictionary *myDateDict = //whatever;

NSString *dateString = myDateDict[@"iso"];
NSDateFormatter *formatter = NSDateFormatter.dateFormat = "<your date format>";
NSDate *date = [formatter dateFromString: dateString];
Duncan C
  • 128,072
  • 22
  • 173
  • 272