核心数据不保存到sqlite数据库

时间:2014-09-08 06:20:49

标签: ios sqlite core-data

我试图寻找答案,但没有任何帮助( 所以我尝试将数据保存在像这样的核心数据中

-(void) insertHeaderCatalogsToDataBase{

    UBCoreDataStack *coreDataStack = [UBCoreDataStack defaultStack];
    UBMenuHeader *menuHeader = [NSEntityDescription insertNewObjectForEntityForName:@"UBMenuHeader" inManagedObjectContext:coreDataStack.managedObjectContext];
    menuHeader.name = @"Комплекты";
    [coreDataStack saveContext];

}

UBCoreDataStack - 是一个从委托到此类的单一类。

@interface UBCoreDataStack : NSObject

+(instancetype) defaultStack;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;

@end

所以当我尝试保存时没有错误,并且hasChanges返回true

- (void)saveContext
{
    NSError *error = nil;
    NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    if (managedObjectContext != nil) {
        if ([managedObjectContext save:&error] == NO) {
            NSLog(@"Error saving: %@\n%@", [error localizedDescription], [error userInfo]);
        }
        if([managedObjectContext hasChanges]){
            NSLog(@"There are some changes");
        }
        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();
        }
    }
}

当我用sqlite数据库打开文件夹时DBname.sqlite没有任何更改,但是sqlite-shm和sqlite-wal有。所以我可能忘了将值传递给sqlite DB

1 个答案:

答案 0 :(得分:0)

抱歉,数据已经到位。 sqlite没有任何变化是正常的,但sqlite-shm和sqlite-wal有。