这就是我实际保存可变数组的方法。
[myMutableArray writeToFile:@"/Users/myUserIdentifier/Desktop/results.plist" atomically:YES];
该数组基本上包含很多单词,我希望Windows用户能够阅读它们,我需要它们返回每个单词的新行。
我尝试在每个单词的末尾添加标签,然后将文件保存在.html中:
[myMutableArray writeToFile:@"/Users/myUserIdentifier/Desktop/results.html" atomically:YES];
实际上文件是可读的,但是标签的格式太差了:
<br>
因此Chrome不会将其理解为“转到新线”。
好吧,相当混乱的解释,希望我能找到一个心灵混乱的灵魂伴侣来理解这些东西!
答案 0 :(得分:0)
您尝试将NSMutableArray保存为数组然后读取但是 既不起作用:
- (void)saveState
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@\"Layers\" ofType:@\"plist\"];
NSMutableDictionary* layersDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
[layersDict setValue:layers forKey:@\"Layers\"];
[layersDict writeToFile:filePath atomically: YES];
}
- (void)loadLastState;
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@\"Layers\" ofType:@\"plist\"];
NSMutableDictionary* layersDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSArray *layersArray = [layersDict objectForKey:@\"Layers\"];
NSMutableArray *layersMutable = [[NSMutableArray alloc] initWithArray:layersArray];
[self recoverFromLayers:layersMutable];
}
答案 1 :(得分:0)
答案 2 :(得分:0)
您只想将包含字符串的数组写入文件?那不需要什么花哨的东西。例如:
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
NSMutableArray *words = [NSMutableArray arrayWithObjects:@"fluffy",@"furball",@"scratcher",nil];
FILE *filePointer = fopen("/Volumes/Weinberg/Users/alan/Desktop/cats.txt","w");
[words enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
fprintf(filePointer,"%s\n",[obj UTF8String]);
}];
fclose(filePointer);
[p release];
}