写入plist时出错 [英] error writing to plist

查看:58
本文介绍了写入plist时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[array writeToFile:[documentsDirectory stringByAppendingPathComponent:@"data.plist" atomically:YES];

此行出现错误,提示未找到方法 -stringByAppendingPathComponent .有什么问题

this line gives error that method -stringByAppendingPathComponent not found. whats the issue

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *array = [[NSArray alloc]initWithObjects:@"First", @"Second", @"Third", nil];
[array writeToFile:[documentsDirectory stringByAppendingPathComponent:@"data.plist" atomically:YES]];

推荐答案

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

NSString *documentsDirectory = [paths objectAtIndex:0]; 

plistpath = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:@"Product.plist"]];

然后

[array writeToFile:path atomically:YES]; 

[Whatever [Array or Dictionary] you want to Write in Plist]

如果仍然没有创建plist,请检查您的数组或字典是否必须为空.

If it is still not creating the plist then check whether your array or dictionary must be empty.

这篇关于写入plist时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆