我试图弄清楚如何将 NSDate 值保存到我的应用程序中的 plist 文件中。
我目前正在这样做,但被困在我必须保存它的实际部分。
NSString *datePlistPath = [[NSBundle mainBundle] pathForResource: @"my-Date" ofType: @"plist"];
NSMutableDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: datePlistPath];
// to be saved to plist
NSDate *date = [NSDate date];
// this is where I start to get abit lost, I want to set the date to the right plist value then commit the changes
[dict setObject:date forKey:@"my-Date"];
[dict writeToFile:datePlistPath atomically:YES]; // error happening here.
任何帮助,将不胜感激
更新:一旦它到达最后一行代码,这就是生成的错误......
* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object”