【深入浅出ios开发】数据存储-----XML属性列表(plist)归档

前端之家收集整理的这篇文章主要介绍了【深入浅出ios开发】数据存储-----XML属性列表(plist)归档前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@ ①存储数据:

@H_502_0@ 1.获得home路径:

@H_502_0@ NSString*home =NSHomeDirectory();

@H_502_0@ 2.通过home路径获得Documents/xxx.plist路径

@H_502_0@ 3.往相应的路径写数据

@H_502_0@

[objc] view plain copy
  1. -(IBAction)save:(id)sender{
  2. NSString*home=NSHomeDirectory();
  3. NSLog(@"%@",home);
  4. NSString*strDocument=[homestringByAppendingPathComponent:@"Documents/xml.plist"];
  5. NSArray*array=@[@"A",@"B",@"C"];
  6. [arraywriteToFile:strDocumentatomically:YES];
  7. }

②读取数据: @H_502_0@

@H_502_0@ 1.获得相应的plist文件的路径

@H_502_0@ 2.直接通过类相应的方法调用读取数据

@H_502_0@

copy
    -(IBAction)read:(NSMutableArray*array=[[NSMutableArrayalloc]initWithContentsOfFile:strDocument];
  1. NSLog(@"%@",array);
  2. }

猜你在找的XML相关文章