このメソッド(saveObject:(id)object forKey:(NSString *)key)を呼び出すと、ファイルが作成されないのはなぜですか?
私がそれを呼び出すと、filePathはnilに等しいので、(-(void)setFilePath:(NSString *)fileName)メソッドが呼び出されます...
-(int) saveObject: (id)object forKey: (NSString *) key {
//save object into file
if(filePath == nil) {
[self setFilePath:nil];
}
mainDict = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
if(mainDict == nil) {
mainDict = [[NSMutableDictionary alloc] init];
}
[mainDict setObject:object forKey:key];
if(![mainDict writeToFile:filePath atomically:YES]) {
if(object == nil) {
return 3;
}
if(key == nil) {
return 4;
}
return 2; //ERROR could not write object to file
} else {
if(shouldUseCache == YES) {
cacheStatus = 2; //New Caches need to be updated
}
return 1; //SUCCESS object saved to file
}
//RETURN KEY's
// *1 SUCCESS object saved to file
// *2 ERROR could not write object to file
// *3 ERROR object variable = nil
// *4 ERROR key variable = nil
}
-(void) setFilePath: (NSString *)fileName {
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex:0];
if(fileName == nil) {
fileName = @"savedObjects";
}
filePath = [NSString stringWithFormat:@"%@/%@.plist",documentsDirectory, fileName];
}