list ---> is a NSMutableArray,
every node in list has "title", "field2", "field3"
So I found that :
[list writeToFile: path atomically:YES]; ----> always return "NO", file not saved
[[[list objectAtIndex:0] title] writeToFile: path atomically:YES]; ---> is fine, so it means the file is accessible.
I know that it is supposed to be [NSArray WriteToFile: Automatically:]
but as document suggested NSMutableArray is extended from NSArray, so I guess it should be fine. Compiler didn't report error on this.
BTW, I also tried to first convert the NSMutableArray back into NSArray, but it crashes the simulator, here is how I do the convert:
NSArray *tmpList;
retVal = [[tmpList initWithArray:list] writeToFile: path atomically:YES];
I just tried to do it with "initWithObjects:list" as well, it also causes the simulator crash:
retVal = [[tmpList initWithObjects:list count: (NSUInteger) [list count]] writeToFileath atomically:YES];
Could someone point out what the problem here with the file saving, thanks in advance.
==================code begin=====================
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent"newslist.txt"];
NSInteger retVal;
retVal = [list writeToFile: path atomically:YES];
//retVal = [@"string" writeToFile: path atomically:YES];
//retVal = [[[list objectAtIndex:0] title] writeToFile: path atomically:YES];
if( retVal==YES ){
// display "Yes"
}else{
// display "NO"
}
every node in list has "title", "field2", "field3"
So I found that :
[list writeToFile: path atomically:YES]; ----> always return "NO", file not saved
[[[list objectAtIndex:0] title] writeToFile: path atomically:YES]; ---> is fine, so it means the file is accessible.
I know that it is supposed to be [NSArray WriteToFile: Automatically:]
but as document suggested NSMutableArray is extended from NSArray, so I guess it should be fine. Compiler didn't report error on this.
BTW, I also tried to first convert the NSMutableArray back into NSArray, but it crashes the simulator, here is how I do the convert:
NSArray *tmpList;
retVal = [[tmpList initWithArray:list] writeToFile: path atomically:YES];
I just tried to do it with "initWithObjects:list" as well, it also causes the simulator crash:
retVal = [[tmpList initWithObjects:list count: (NSUInteger) [list count]] writeToFileath atomically:YES];
Could someone point out what the problem here with the file saving, thanks in advance.
==================code begin=====================
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent"newslist.txt"];
NSInteger retVal;
retVal = [list writeToFile: path atomically:YES];
//retVal = [@"string" writeToFile: path atomically:YES];
//retVal = [[[list objectAtIndex:0] title] writeToFile: path atomically:YES];
if( retVal==YES ){
// display "Yes"
}else{
// display "NO"
}