2012-09-18 18 views
0

這就是我如何實際保存可變數組。保存除Plist以外的其他類型的IOS

[myMutableArray writeToFile:@"/Users/myUserIdentifier/Desktop/results.plist" atomically:YES]; 

數組包含基本多的話,我希望Windows用戶能夠讀取他們,我需要他們回去每個字一個新的生產線。

我試圖在每一個單詞的末尾添加標記,然後保存以html文件:

[myMutableArray writeToFile:@"/Users/myUserIdentifier/Desktop/results.html" atomically:YES]; 

實際上該文件是可讀的,但太糟糕的標籤已被格式化,像這樣:

<br> 

因此,Chrome並不把它理解爲「去換新路線」。

好吧,相當搞砸的解釋,希望我會找到一個靈魂伴侶用一個凌亂的頭腦來理解所有這些東西!

回答

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]; 
} 
+0

工程就像一個魅力! – user1183716

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]; 
} 
0

MHH不是真的。一切正常。我只想格式化我的結果,使其在啓動保存的文件時對Windows用戶更清晰一些。到目前爲止,html是最好的。但是我被這些標籤卡住了。也許有另一種簡單的方法來獲取文本文件,每一個字都會進入下一行。

相關問題