开发者

How to store an NSDictionary to disk and read back in?

I'm getting an NSDictionary from the user defaults database which has key-value pairs of user settings. So the same content as NSUser开发者_开发技巧Defaults dictionary has.

NSLog(@"%@ defaults = %@", [self class], 
  [[NSUserDefaults standardUserDefaults] 
   persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]]);

What would be the easiest way to persist that guy to disk and read back in as NSDictionary?


NSDictionary has the writeToFile:atomically: method to store it and the dictionaryWithContentsOfFile method to read it back in.

EDIT : THe article linked to in The MYYN's answer has a few good examples of this ;)


Article on Serialization in Cocoa - Property Lists:

  • http://www.cocoacast.com/?q=node/167

Property Lists are very useful for passing information between processes, storing configuration parameters, and much more. It’s a very powerful concept that nicely expands Mac and iPhone OS serialization and configuration capabilities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜