Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Restkit&x2B;查找sql文件时出现的神奇记录问题_Ios_Objective C_Core Data_Restkit_Magicalrecord - Fatal编程技术网

Ios Restkit&x2B;查找sql文件时出现的神奇记录问题

Ios Restkit&x2B;查找sql文件时出现的神奇记录问题,ios,objective-c,core-data,restkit,magicalrecord,Ios,Objective C,Core Data,Restkit,Magicalrecord,我正在尝试使用restkit的神奇记录 因此,我已按照以下URL进行了设置: 我的问题是,如果我尝试使用Magic record创建一个记录,我总是在它第一次尝试保存任何内容时出现以下错误。如果我关闭应用程序并重新启动,就可以了 +MagicalRecord(ErrorHandling)defaultErrorHandler:错误:/var/mobile/Containers/Data/Application/1CECA7F7-510F-47F2-9F2D-4D0346C4E74F/Docum

我正在尝试使用restkit的神奇记录

因此,我已按照以下URL进行了设置:

我的问题是,如果我尝试使用Magic record创建一个记录,我总是在它第一次尝试保存任何内容时出现以下错误。如果我关闭应用程序并重新启动,就可以了

+MagicalRecord(ErrorHandling)defaultErrorHandler:错误:/var/mobile/Containers/Data/Application/1CECA7F7-510F-47F2-9F2D-4D0346C4E74F/Documents/WhateverModel.sqlite

这意味着它找不到该文件。所以我检查了文件夹,是的,它不在那里,即使我指示restkit设置它

知道我为什么会得到这个吗

下面是设置代码

NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Model" ofType:@"momd"]];
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Model.sqlite"];
NSError *error = nil;
[managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil withConfiguration:nil options:nil error:&error];
[managedObjectStore createManagedObjectContexts];

// Configure MagicalRecord to use RestKit's Core Data stack
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:managedObjectStore.persistentStoreCoordinator];
[NSManagedObjectContext MR_setRootSavingContext:managedObjectStore.persistentStoreManagedObjectContext];
[NSManagedObjectContext MR_setDefaultContext:managedObjectStore.mainQueueManagedObjectContext];

RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]];
objectManager.managedObjectStore = managedObjectStore;
在下面创建和保存对象:

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
    WhateverObject *obj = [WhateverObject createInContext:localContext];
}completion:^(BOOL successful, NSError *error) {

    if(successful){

    }else{

    }
}];

我删除了魔法记录,并使用以下设置:

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]];

NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
manager.managedObjectStore = managedObjectStore;
/**
 Complete Core Data stack initialization
 */
[managedObjectStore createPersistentStoreCoordinator];

NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"WhateverModel.sqlite"];

NSError *error;

NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil  withConfiguration:nil options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error];

NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);

// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];

// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];

您是如何指示RestKit进行设置的?我在问题中的“显示您的代码”中跟踪了该项目,包括设置和保存,并显示完整的错误消息和堆栈跟踪。您好,基本上,我认为问题在于我正在使用Magic record创建对象并保存。为此,我使用存储块。[MagicalRecord saveWithBlock:^(NSManagedObjectContext*localContext)您可能需要在创建managedObjectStore后立即调用[managedObjectStore createPersistentStoreCoordinator];在创建managedObjectStore之后