加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 09:13:30 所属栏目:百科 来源:网络整理
导读:①存储数据: 1.获得home路径: NSString *home = NSHomeDirectory (); 2.通过home路径获得Documents/xxx.plist路径 3.往相应的路径写数据 [objc] view plain copy -(IBAction)save:( id )sender{ NSString *home=NSHomeDirectory(); NSLog( @"%@" ,home); N

①存储数据:

1.获得home路径:

NSString*home =NSHomeDirectory();

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

3.往相应的路径写数据

[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. }

②读取数据:

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读