将 __NSCFDictionary 转换为 NSDate

Converting __NSCFDictionary to NSDate

我正在通过 NSDictionary 传递一个 NSDate 作为推送通知发送给另一个 user/multiple 用户。我正在尝试获取通过推送通知发送的 NSDate 并将其转换回 NSDate,但该对象不断以 __NSCFDictionary 的形式出现,这显然是我不知道的不想。我打印出 NSDictionary 键 "time" 的样子,这就是输出的内容。

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

如何将此 __NSCFDictionary 转换为 NSDate

你的陈述很清楚地表明你并不真正知道字典和日期之间的区别。您发布的数据是一个包含 2 key/value 对的字典,其中一个包含日期字符串。您需要获取 "iso" 键的值并使用日期格式化程序将其转换为日期。

NSDictionary *myDateDict = //whatever;

NSString *dateString = myDateDict[@"iso"];
NSDateFormatter *formatter = NSDateFormatter.dateFormat = "<your date format>";
NSDate *date = [formatter dateFromString: dateString];