iphone - 我应该使用哪种文件格式将数组保存到文件中?

标签 iphone ios objective-c file-io nsarray

我正在使用此处找到的解决方案:Save NSArray to File我只是想知道我应该将数组保存为哪种类型的文件格式。我可以只使用 .txt 吗?

最佳答案

任何格式。 iOS writeToPath: 不读取扩展。您甚至可以编写奇怪的文件名。

以您引用问题中的代码为例,

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:FILE_NAME];

[myArray writeToFile:filePath atomically:YES];

FILE_NAME 可以是任何 ASCII 值。

关于iphone - 我应该使用哪种文件格式将数组保存到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18458023/

相关文章:

iphone - 如何在 Storyboard中连接 UIPickerView 数据源和委托(delegate)

iphone - 获取图像大小而不加载到内存

iphone - MBProgressHUD 崩溃 "The view used in the MBProgressHUD initializer is nil"

iphone - 如何在 iPhone cocos2d 中移动水?

ios - CoreData 将对象添加到一对多关系错误

ios - 告诉按钮我们正在点击 tableView 的哪一行

ios - iOS 7 中的图像解压缩

ios - 如何防止 iphone 的 jquery 移动应用程序在 ipad 中自动拉伸(stretch)

objective-c - 在公共(public) API 中使用 'id' 作为返回类型或参数类型有什么好的理由吗?

ios - 将 NSArray 放入 TableView