我想讀取輸入文件(如果存在),然後想要添加一個字符串到該輸入。我的代碼如下所示。如何將對象添加到NSMutableArray
NSMutableArray *listData = [[NSMutableArray alloc] initWithContentsOfFile:*filepath*];
// listData = null if the input file does not exist.
NSString *jobName = [NSString stringWithFormat:@"My New Job"];
[listData addObject:jobName];
如果輸入的存在,那麼後ADDOBJECT:作業名稱,則的ListData已經更新,但如果輸入文件不存在的ListData後ADDOBJECT仍然給空:JOBNAME。我的輸入文件(如果存在)看起來像。
<array>
<string>My Job 1</string>
<string>My Job 2</string>
<string>My Job 3</string>
</array>
我想補充的串串現有陣列中或要創建的字符串的工作名的新數組,如果它已不存在。有人可以幫我嗎?當輸入文件不存在時,我應該使用哪種方法創建新的字符串數組。
非常感謝你戴夫德隆。它幫助了我。 – UCU110 2010-08-13 20:43:25