У меня был способ сохранить диск на диск:
+(BOOL) writeApplicationData:(NSDictionary *)data
bwriteFileName:(NSString *)fileName
{
NSLog(@"writeApplicationData");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return NO;
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
return ([data writeToFile:appFile atomically:YES]);
}
И я проверил это с:
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSMutableDictionary *d1 = [[NSMutableDictionary alloc] init];
NSMutableDictionary *d2 = [[NSMutableDictionary alloc] init];
[d1 setObject:@"d11"
forKey:@"d11"];
[d1 setObject:@"d12"
forKey:@"d12"];
[d1 setObject:@"d13"
forKey:@"d13"];
[d2 setObject:@"d21"
forKey:@"d21"];
[d2 setObject:@"d22"
forKey:@"d22"];
[d2 setObject:@"d23"
forKey:@"d23"];
[dic setObject:d1
forKey:@"d1"];
[dic setObject:d2
forKey:@"d2"];
[self writeApplicationData:dic
bwriteFileName:@"testSave"];
И данные сохранены правильно.
Затем я попытался сохранить d1 с классом obj:
LevelInfoData *levelInfoData = [[LevelInfoData alloc] init];
[levelInfoDictionary setObject:levelInfoData
forKey:@"test"];
[dic setObject:levelInfoDictionary
forKey:@"LevelInfoDictionary"];
Но на этот раз даже файл plist не был создан на диске.
Вот класс LevelInfoData:
@interface LevelInfoData : NSObject {
int levelNum;
}
@property (nonatomic) int levelNum;
@end
@implementation LevelInfoData
@synthesize levelNum;
@synthesize isLevelLocked;
@synthesize isLevelCleared;
@synthesize levelHighScore;
-(id)init
{
if( (self = [super init]) ) {
levelNum = 0;
}
return self;
}
@end
Я действительно запутался, надеюсь, кто-нибудь может мне помочь, спасибо.