2010-05-20 23 views
0

,並再次我的陣列陣列...我嘗試通過在文件以備後用緩衝陣列來提高我的應用程序的性能。- 寫文件的問題

我有一個包含的NSNumber,NSDate的和NSString對象約30 NSMutableArrays一個NSMutableArray。

我嘗試使用此調用寫入文件:

bool result = [myArray writeToFile:[fileMethods 
            getFullPath:[NSString 
               stringWithFormat:@"iEts%@.arr", 
               [aDate shortDateString]]] 
         atomically:NO]; 

=>結果= FALSE。

的路徑的方法是:

+ (NSString *) getFullPath:(NSString *)forFileName { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    return [documentsDirectory stringByAppendingPathComponent:forFileName]; 
} 

和ADATE調用返回與日月年一shortDateString。

的NSLog的

NSLog(@"%@", [fileMethods getFullPath:[NSString stringWithFormat:@"iEts%@.arr", 
               [aDate shortDateString]]]); 

的路徑生成回報:

/Users/me/Library/Application Support/iPhone Simulator/User/Applications/86729620-EC1D-4C10-A799-0C638BB27933/Documents/iEts010510.arr 

進一步指出:

  • 它必須有事情做與 陣列陣列,因爲我也寫3 更簡單的數組(包含 NSStrings),都取得成功。
  • 數組的數組被使用AddObject方法

任何想法可能會導致麻煩產生的?

回答

1

你有沒有在你的數組中的任何NSNulls?我認爲它們不算作plist對象,因此會導致寫入失敗。

+0

我在數組中有空字符串,但是當我測試填充它們時,數組存儲仍然失敗 - 情況不變 – iFloh 2010-05-20 13:18:39

2

AFAIK寫入到文件使用對象歸檔因此你的陣列的陣列中的一些對象不能被歸檔。

+0

屬性列表,而不是對象存檔。但是,同樣的總體效果。 – 2010-05-20 06:40:29

+0

嗯,我跟着你的領導,開始測試寫子陣列。看起來有空NSStrings的人寫不出來。添加一個空格字符也不會幫助... – iFloh 2010-05-20 07:00:10

+0

不明白。 NSNumber,NSDate和NSString都不會作爲麻煩製造者報告。用一些文字填充我的空字符串也不會改變任何東西......奇怪。在我的子數組枚舉中,當1個對象被連接時,它寫入子陣列,從第二個對象開始它失敗... – iFloh 2010-05-20 08:16:34