Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2108345
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: 嵌入式

2011-09-12 16:07:05

  1. Docs
  2. Summary
    Mac OS X applications use XML propertylists (or plists) for storing things such as your
    default preferences, application settings, and configuration information.
  3. Read/Write
    • If your objects are of type  NSString , NSDictionary , NSArray , NSDate , NSData , or NSNumber , you can use the  writeToFile:atomically: method implemented in these
      classes to write your data to a file.

      Sample:
      Write to file:
      NSDictionary  *glossary;
      ....
      if ([glossary writeToFile: @ "glossary" atomically: YES] == NO)
          NSLog (@ "Save to file failed!");

      Read from file:
      NSDictionary *glossary;
      glossary = [NSDictionary dictionaryWithContentsOfFile: @ "glossary "];
      for ( NSString *key in glossary )
          NSLog (@"%@: %@ " ,  key, [glossary objectForKey: key]);
       

    • A more flexible approach enables you to save any type of objects to a file, not just strings, arrays, and dictionaries. This is done by creating a keyed archive using the NSKeyedArchiver class.

      Sample:
      Write to file:
      NSDictionary *glossary;
      ......
      [NSKeyedArchiver archiveRootObject: glossary toFile: @ "glossary.archive"];

      Read from file:
      NSDictionary *glossary;
      glossary = [NSKeyedUnarchiver unarchiveObjectWithFile:@"glossary.archive"];
      for ( NSString *key in glossary )
          NSLog (@ ” %@: %@ ” ,  key, [glossary objectForKey: key]);

  4. xxx

阅读(675) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~