Converting NSDate to NSString causes unrecognized selector exception

廉价感情. 提交于 2019-12-02 03:45:27

You are overcomplicating things. What makes you think that storing a NSDate object you'll get back a NSString?

Just do

NSDate * checkDate = [InfoDic objectForKey:@"LastDate"];

Also, don't confuse KVC methods with NSDictionary methods.

You want to use setObject:forKey: instead of setValue:forKey if you don't want to face bad surprises.

You are not storing a date as a string in the plist, you are storing it as a date.

The line:

[InfoDic setValue:[NSDate date] forKey:@"LastDate"];

stores the actual NSDate object.

All you need to get it back out is to call:

NSDate *theDay = InfoDic[@"LastDate"];

BTW - the line:

[InfoDic setValue:[NSDate date] forKey:@"LastDate"];

should be:

[InfoDic setObject:[NSDate date] forKey:@"LastDate"];

or just:

InfoDic[@"LastDate"] = [NSDate date];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!