オブジェクトをファイルに保存する次のコードがあります...
-(int) saveObject: (id)object forKey: (NSString *) key
{
//save object into file
NSLog(@"PRESENT");
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])
{
return 2; //ERROR could not write object to file
if(object == nil) {
return 3;
}
if(key == nil) {
return 4;
}
}
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
}
ご覧のとおり、メソッドは明らかに1から4までの数値を返すはずですが、View Controllerでメソッドを呼び出すと、0になります???
最も奇妙な部分は、コンソールにNSLog(@ "Present")が表示されないことです。
問題は何ですか、これを引き起こす原因は何ですか?
これが私のシンプルなビューコントローラです...
NSLog(@"%d",[mainDict saveObject:@"HELLO" forKey:@"foo"]);
私の.hファイルも...
#import <UIKit/UIKit.h>
#import "ObjectSaver.h"
@interface ViewController : UIViewController {
ObjectSaver *mainDict;
}