【深入浅出ios开发】数据存储-----XML属性列表(plist)归档
发布时间:2020-12-16 05:48:57 所属栏目:百科 来源:网络整理
导读:①存储数据: 1.获得home路径: NSString *home = NSHomeDirectory (); 2.通过home路径获得Documents/xxx.plist路径 3.往相应的路径写数据 - (IBAction)save:(id)sender { NSString *home = NSHomeDirectory(); NSLog(@"%@",home); NSString *strDocument =
①存储数据: 1.获得home路径: NSString *home = NSHomeDirectory(); 2.通过home路径获得Documents/xxx.plist路径 3.往相应的路径写数据
- (IBAction)save:(id)sender { NSString *home = NSHomeDirectory(); NSLog(@"%@",home); NSString *strDocument = [home stringByAppendingPathComponent:@"Documents/xml.plist"]; NSArray *array = @[@"A",@"B",@"C"]; [array writeToFile:strDocument atomically:YES]; } ②读取数据: 1.获得相应的plist文件的路径 2.直接通过类相应的方法调用读取数据
- (IBAction)read:(id)sender { NSString *home = NSHomeDirectory(); NSLog(@"%@",home); NSString *strDocument = [home stringByAppendingPathComponent:@"Documents/xml.plist"]; NSMutableArray *array = [[NSMutableArray alloc]initWithContentsOfFile:strDocument]; NSLog(@"%@",array); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |