核心数据:数据库无法正确读取

时间:2015-03-16 21:54:41

标签: ios objective-c sqlite core-data

我试图从我的核心数据数据库加载NSData,但是如果我比较这两个文件,原始数据库与保存的数据相比,数据甚至远远接近显示的内容从NSData加载,从NSData保存的那个根本没有任何数据,只有表结构。

这是我的来源,而且非常基础:

NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    if (managedObjectContext != nil) {
        NSError *error = nil;
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
            // Replace this implementation with code to handle the error appropriately.
            // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }
    }

NSString *path = [AppDelegate instance].databaseDirectory.path;
NSData *file   = [[NSFileManager defaultManager] contentsAtPath:path];
[file writeToFile:[AppDelegate instance].tempDatabaseDirectory.path atomically:NO];

0 个答案:

没有答案