Ios 将NSArray的内容保存为纯文本文件而不是xml

Ios 将NSArray的内容保存为纯文本文件而不是xml,ios,objective-c,xcode5,nsarray,Ios,Objective C,Xcode5,Nsarray,我正在尝试将NSArray的内容保存为纯文本文件。下面是我如何保存数组内容的: [myArrayContent writeToFile:filePath atomically:YES]; 但已另存为xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.

我正在尝试将NSArray的内容保存为纯文本文件。下面是我如何保存数组内容的:

[myArrayContent writeToFile:filePath atomically:YES];
但已另存为xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <string>lineOne</string>
    <string>lineTwo</string>
</array>
</plist>

一线
第二行
我想问你们的问题是,我如何将内容保存为纯文本:

一线 第二行

你们中有谁知道如何实现这一点


非常感谢您的帮助。

如果数组中的对象是NSStrings,您应该迭代数组中的对象,并在每次迭代中写入字符串,就像处理数组一样。

您可以将数组制作成字符串,然后保存,如下所示:

NSString *fileContent = [myArrayContent componentsJoinedByString: @"\n"];
[fileContent writeToFile:filePath atomically:YES];
NSArray *myArrayContent = [
    [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]
    componentsSeparatedByString:@"\n"
];
回溯是这样做的:

NSString *fileContent = [myArrayContent componentsJoinedByString: @"\n"];
[fileContent writeToFile:filePath atomically:YES];
NSArray *myArrayContent = [
    [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]
    componentsSeparatedByString:@"\n"
];

不推荐使用,现在您可以使用类似于[fileContent WriteFile:[self filepath]的原子方式:YES编码:NSUTF8StringEncoding错误:&err];