[英]RestKit Mapping Invalid parameter not satisfying: managedObjectStore
Possible duplication : RestKit Core Data 'managedObjectStore is nil' 可能的重复: RestKit核心数据“ managedObjectStore为零”
Could somebody explain me why when I run my application I get error like : 有人可以解释一下为什么我在运行应用程序时出现如下错误:
- Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ' Invalid parameter not satisfying: managedObjectStore' *** First throw call stack
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:' 无效的参数不令人满意:managedObjectStore' ***第一个throw调用堆栈
It happened to me only in my MainViewController when I'm calling the following method: 当我调用以下方法时,它仅在MainViewController中发生:
-(void)loadLocationsOfWearers{
RKManagedObjectStore *store = [[DateModel sharedDataModel] objectStore];
NSIndexSet *statusCodeSet= RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKMapping *mapping = [MappingProvider watchesMapping];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:nil keyPath:@"watch" statusCodes:statusCodeSet];
NSURL *url = [NSURL URLWithString:kSERVER_ADDR];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKManagedObjectRequestOperation *operation =[[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
operation.managedObjectCache = store.managedObjectCache;
operation.managedObjectContext = store.mainQueueManagedObjectContext;
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
_wearerList = mappingResult.array;
NSLog(@"Results:\n %@",mappingResult.dictionary);
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"ERROR: %@", error);
NSLog(@"Response: %@", operation.HTTPRequestOperation.responseString);
}];
[operation start];
}
When I'm calling this method in other ViewControllers everything works fine. 当我在其他ViewControllers中调用此方法时,一切正常。 It looks like my managedObjectStore is nil, but I don't know what is the reason for that... Please take a look at my DateModel code and share with me your ideas:
看来我的managedObjectStore为零,但我不知道是什么原因...请看一下我的DateModel代码并与我分享您的想法:
@implementation DateModel
+ (id)sharedDataModel
{
static DateModel *__sharedDataModel = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__sharedDataModel = [[DateModel alloc] init];
});
return __sharedDataModel;
}
- (NSManagedObjectModel *)managedObjectModel
{
return [NSManagedObjectModel mergedModelFromBundles:nil];
}
- (id)optionsForSqliteStore
{
return @{
NSInferMappingModelAutomaticallyOption: @YES,
NSMigratePersistentStoresAutomaticallyOption: @YES
};
}
- (void)setup
{
self.objectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSString *path = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Data.sqlite"];
NSLog(@"Setting up store at %@", path);
NSError *error;
[self.objectStore addSQLitePersistentStoreAtPath:path
fromSeedDatabaseAtPath:nil
withConfiguration:nil
options:[self optionsForSqliteStore]
error:&error];
[self.objectStore createManagedObjectContexts];
self.objectStore.managedObjectCache =[[RKInMemoryManagedObjectCache alloc]initWithManagedObjectContext:self.objectStore.persistentStoreManagedObjectContext];
[RKManagedObjectStore setDefaultStore:self.objectStore];
}
In my AppDelegate method I just simply setup my store. 在我的AppDelegate方法中,我只是简单地设置商店。
-(void)setupCoreData
{
[[DateModel sharedDataModel]setup];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setupCoreData];
}
When I run my application I'm getting error like on the screen below: 运行我的应用程序时,出现以下屏幕错误:
+(RKMapping *)watchesMapping
{
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Watches" inManagedObjectStore:[[DateModel sharedDataModel]objectStore]];
[mapping addAttributeMappingsFromDictionary:@{
@"id": @"watch_id",
@"altitude":@"altitude",
@"battery_life":@"battery_life",
@"button_press_time":@"button_press_time",
@"charging_status":@"charging_status",
@"gmaps":@"gmaps",
@"id_addr":@"id_addr",
@"last_keep_alive":@"last_keep_alive",
@"last_update_time":@"last_update_time",
@"latitude":@"latitude",
@"longitude":@"longitude",
@"location":@"location",
@"network":@"network",
@"phonewatchno":@"phonewatchno",
@"rssi":@"rssi",
@"short_imei":@"short_imei",
@"updated_at":@"updated_at",
@"voltage":@"voltage",
@"waerer_id":@"wearer_id",
@"updated_at":@"updated_at",
@"token":@"token"
}
];
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"alerts" toKeyPath:@"alerts" withMapping:[MappingProvider alertsMapping]]];
return mapping;
}
loadLocationsOfWearers
is being called too soon (before setupCoreData
is called). loadLocationsOfWearers
的调用时间过早(在setupCoreData
之前)。 Call it later, or call setupCoreData
when the data model singleton is created. 稍后调用它,或者在创建数据模型单例时调用
setupCoreData
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.