好用的兩個讀取寫入function
- (BOOL) writeToFile:(NSString *)filename writeData:(NSMutableArray *)data{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, filename];
return [data writeToFile:fileName atomically:NO];
}
- (BOOL) loadFromFile:(NSString *)filename writeData:(NSMutableArray *)data{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, filename];
[data addObjectsFromArray:[NSMutableArray arrayWithContentsOfFile:fileName]];
return 0;
}