iOS RestKit问题:无效参数不满足:responseDescriptors

iOS RestKit问题:无效参数不满足:responseDescriptors,ios,xcode,restkit,Ios,Xcode,Restkit,我正在尝试使用RestKit检索事件列表,我一直得到以下结果: 2013-05-20 10:52:56.708 EventApp[3380:c07] I restkit:RKLog.m:34 RestKit logging initialized... 2013-05-20 10:52:56.773 EventApp[3380:c07] *** Assertion failure in -[RKObjectRequestOperation initWithRequest:responseD

我正在尝试使用RestKit检索事件列表,我一直得到以下结果:

2013-05-20 10:52:56.708 EventApp[3380:c07] I restkit:RKLog.m:34 RestKit logging initialized...
2013-05-20 10:52:56.773 EventApp[3380:c07] *** Assertion failure in    -[RKObjectRequestOperation initWithRequest:responseDescriptors:], /Users/mitchell/Desktop/eventapp/take2/EventApp/Pods/RestKit/Code/Network/RKObjectRequestOperation.m:158
2013-05-20 10:52:56.774 EventApp[3380:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: responseDescriptors' 
这件事我已经挠了好几天了。由于我在iOS开发技能方面有相当大的差距(每年大约有一个项目),如果有人能用一些外行术语引导我朝着正确的方向前进,这将非常有帮助

请考虑我想使用eNeaveObjtReQuestStand专门用于批处理多个请求。我刚刚拼凑了一些代码,在这里进行翻译

以下是我的数据模型的外观:

[{
"id":1,
"farm_id":1,
"all_day": "NO",
"from": "2013-05-08T18:45:38Z",
"to": "2013-05-08T18:45:38Z",
"name": "event 1",
"desc": "some description",
"photo": "some.png",
"price": "price"
}]

以下是JSON文件的外观:

[{
"id":1,
"farm_id":1,
"all_day": "NO",
"from": "2013-05-08T18:45:38Z",
"to": "2013-05-08T18:45:38Z",
"name": "event 1",
"desc": "some description",
"photo": "some.png",
"price": "price"
}]
这是我的密码:

NSManagedObjectContext *context;

RKObjectManager *objectManager;
if (self.eventContext == nil) {
    NSError *error = nil;
    NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"FarmApp" ofType:@"momd"]];
    RKEntityMapping *entityMapping;
    // NOTE: Due to an iOS 5 bug, the managed object model returned is immutable.
    NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];

    RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];

    // Initialize the Core Data stack
    [managedObjectStore createPersistentStoreCoordinator];

    NSPersistentStore __unused *eventPersistentStore = [managedObjectStore addInMemoryPersistentStore:&error];
    NSAssert(eventPersistentStore, @"Failed to add persistent store: %@", error);

    [managedObjectStore createManagedObjectContexts];

    // Set the default store shared instance
    [RKManagedObjectStore setDefaultStore:managedObjectStore];

    // Configure the object manager
    RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://sandbox.bm.com"]];

    [RKObjectManager setSharedManager:objectManager];

    [objectManager setRequestSerializationMIMEType:@"application/json"];
    [objectManager setAcceptHeaderWithMIMEType:@"text/plain"];

    objectManager.managedObjectStore = managedObjectStore;
        entityMapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:managedObjectStore];
        [entityMapping addAttributeMappingsFromDictionary:@{
         @"id":             @"eventID",
         @"farm_id":        @"farm",
         @"all_day":        @"allDay",
         @"from":           @"from",
         @"to":             @"to",
         @"name":           @"name",
         @"desc":           @"desc",
         @"photo":          @"photo",
         @"price":          @"price"
         }];        
    RKResponseDescriptor *successDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

    [objectManager addResponseDescriptor:successDescriptor];

    RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:@"errors" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];

    [objectManager addResponseDescriptor:errorDescriptor];
    self.eventContext = managedObjectStore.mainQueueManagedObjectContext;

}
context = self.eventContext;
NSString* url = [NSString stringWithFormat:@"http://sandbox.bm.com/farmapp/%@.json", @"events"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:[objectManager responseDescriptors]];
[operation setCompletionBlockWithSuccess:nil failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Loaded this error: %@", [error localizedDescription]);
}];
NSArray *operations = [NSArray arrayWithObjects:operation, nil];
for (int i = 0; i < [operations count]; i++ ) {
    [[RKObjectManager sharedManager] enqueueObjectRequestOperation:[operations objectAtIndex:i]];
}
NSManagedObjectContext*上下文;
RKObjectManager*objectManager;
if(self.eventContext==nil){
n错误*错误=nil;
NSURL*modelURL=[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“FarmApp”类型:@“momd”];
RKEntityMapping*实体映射;
//注意:由于iOS 5错误,返回的托管对象模型是不可变的。
NSManagedObjectModel*managedObjectModel=[[NSManagedObjectModel alloc]initWithContentsOfURL:modelURL]mutableCopy];
RKManagedObjectStore*managedObjectStore=[[RKManagedObjectStore alloc]initWithManagedObjectModel:managedObjectModel];
//初始化核心数据堆栈
[managedObjectStore createPersistentStoreCoordinator];
NSPersistentStore u_unused*eventPersistentStore=[managedObjectStore addInMemoryPersistentStore:&错误];
NSAssert(eventPersistentStore,@“未能添加永久存储:%@”,错误);
[managedObjectStore CreateManagedObjectContext];
//设置默认存储共享实例
[RKSManagedObjectStore setDefaultStore:managedObjectStore];
//配置对象管理器
RKObjectManager*objectManager=[RKObjectManager管理器WithBaseURL:[NSURL URLWithString:@]http://sandbox.bm.com"]];
[RKObjectManager设置共享管理器:objectManager];
[objectManager setRequestSerializationMIMEType:@“应用程序/json”];
[objectManager setAcceptHeaderWithMIMEType:@“文本/普通”];
objectManager.managedObjectStore=managedObjectStore;
entityMapping=[RKEntityMappingForEntityForName:@“事件”位于managedObjectStore:managedObjectStore];
[entityMapping addAttributeMappingsFromDictionary:@{
@“id”:@“eventID”,
@“农场id”:@“农场”,
@“全天”:“全天”,
@“from”:@“from”,
@“致”:@“致”,
@“名称”:@“名称”,
@“描述”:@“描述”,
@“照片”:“照片”,
@“价格”:“价格”
}];        
RKResponseDescriptor*successDescriptor=[RKResponseDescriptor ResponseDescriptor WithMapping:entityMapping pathPattern:nil keyPath:nil状态代码:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:successDescriptor];
RKResponseDescriptor*errorDescriptor=[RKResponseDescriptor ResponseDescriptor WithMapping:entityMapping pathPattern:nil keyPath:@“错误”状态代码:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];
[objectManager addResponseDescriptor:errorDescriptor];
self.eventContext=managedObjectStore.mainQueueManagedObjectContext;
}
context=self.eventContext;
NSString*url=[NSString stringWithFormat:@”http://sandbox.bm.com/farmapp/%@.json“,@“事件”];
NSURLRequest*request=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
RKObjectRequestOperation*操作=[[RKObjectRequestOperation alloc]initWithRequest:request-responseDescriptors:[objectManager-responseDescriptors]];
[操作setCompletionBlockWithSuccess:nil失败:^(RKObjectRequestOperation*操作,NSError*错误){
NSLog(@“加载此错误:%@,[error localizedDescription]);
}];
NSArray*operations=[NSArray arrayWithObjects:operation,nil];
对于(int i=0;i<[运算计数];i++){
[[RKObjectManager sharedManager]排队ObjectRequestOperation:[operations objectAtIndex:i]];
}
外面有人能帮我吗

这是最终解决方案

if (self.eventContext == nil) {
    NSManagedObjectContext *context;
    RKObjectManager *objectManager;
    NSError *error = nil;
    NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"FarmApp" ofType:@"momd"]];
    RKEntityMapping *entityMapping;
    // NOTE: Due to an iOS 5 bug, the managed object model returned is immutable.
    NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];

    RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];

    // Initialize the Core Data stack
    [managedObjectStore createPersistentStoreCoordinator];

    NSPersistentStore __unused *eventPersistentStore = [managedObjectStore addInMemoryPersistentStore:&error];
    NSAssert(eventPersistentStore, @"Failed to add persistent store: %@", error);

    [managedObjectStore createManagedObjectContexts];

    // Set the default store shared instance
    [RKManagedObjectStore setDefaultStore:managedObjectStore];

    // Configure the object manager
    objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://sandbox.bm.com"]];

    [RKObjectManager setSharedManager:objectManager];

    [objectManager setRequestSerializationMIMEType:@"application/json"];
    [objectManager setAcceptHeaderWithMIMEType:@"text/plain"];

    objectManager.managedObjectStore = managedObjectStore;
    entityMapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:managedObjectStore];
    [entityMapping addAttributeMappingsFromDictionary:@{
     @"id":             @"eventID",
     //@"farm_id":        @"farm",-->cannot create relationship this way
     @"farm_id" :       @"farmID",//farmID attribute needs to be added to Event's model
     @"all_day":        @"allDay",
     @"from":           @"from",
     @"to":             @"to",
     @"name":           @"name",
     @"desc":           @"desc",
     @"photo":          @"photo",
     @"price":          @"price"
     }];

    [entityMapping addConnectionForRelationship:@"farm" connectedBy:@"farmID"];

    RKResponseDescriptor *successDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:@"events" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

    [objectManager addResponseDescriptor:successDescriptor];

    RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:@"errors" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];

    [objectManager addResponseDescriptor:errorDescriptor];

    self.eventContext = managedObjectStore.mainQueueManagedObjectContext;
    context = self.eventContext;
    NSString* url = [NSString stringWithFormat:@"http://sandbox.bm.com/farmapp/%@.json", @"events"];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
            NSLog(@"Success");
        } failure:^(RKObjectRequestOperation *operation, NSError *error) {
                NSLog(@"Failure");
        }];
    NSArray *operations = [NSArray arrayWithObjects:operation, nil];
    for (int i = 0; i < [operations count]; i++ ) {
        [[RKObjectManager sharedManager] enqueueObjectRequestOperation:[operations objectAtIndex:i]];
    }

}
if(self.eventContext==nil){
NSManagedObjectContext*上下文;
RKObjectManager*objectManager;
n错误*错误=nil;
NSURL*modelURL=[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“FarmApp”类型:@“momd”];
RKEntityMapping*实体映射;
//注意:由于iOS 5错误,返回的托管对象模型是不可变的。
NSManagedObjectModel*managedObjectModel=[[NSManagedObjectModel alloc]initWithContentsOfURL:modelURL]mutableCopy];
RKManagedObjectStore*managedObjectStore=[[RKManagedObjectStore alloc]initWithManagedObjectModel:managedObjectModel];
//初始化核心数据堆栈
[managedObjectStore createPersistentStoreCoordinator];
NSPersistentStore u_unused*eventPersistentStore=[managedObjectStore addInMemoryPersistentStore:&错误];
NSAssert(eventPersistentStore,@“未能添加永久存储:%@”,错误);
[managedObjectStore CreateManagedObjectContext];
//设置默认存储共享实例
[RKSManagedObjectStore setDefaultStore:managedObjectStore];
//配置对象管理器
objectManager=[RKObjectManager Manager WithBaseUrl:[NSURL URLWithString:@]http://sandbox.bm.com"]];
[RKObjectManager设置共享管理器:objectManager];
[objectManager setRequestSerializationMIMEType:@“应用程序/json”];
[objectManager setAcceptHeaderWithMIMEType:@“文本/普通”];
objectManager.managedObjectStore=managedObjectStore;
entityMapping=[RKEntityMappingForEntityForName:@“事件”位于managedObjectStore:managedObjectStore];
[entityMapping addAttributeMappingsFromDictionary:@{
@“id”:@“eventID”,
//@“farm_id”:@“farm”,-->无法以这种方式创建关系
@“farm_id”:@“farmID”,//farmID属性n
@"farm_id": @"farm"
RKEntityMapping* eventMapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:managedObjectStore];
[entityMapping addAttributeMappingsFromDictionary:@{
 @"id":             @"eventID",
 //@"farm_id":        @"farm",-->cannot create relationship this way
 @"farm_id" :       @"farmID",//farmID attribute needs to be added to Event's model
 @"all_day":        @"allDay",
 @"from":           @"from",
 @"to":             @"to",
 @"name":           @"name",
 @"desc":           @"desc",
 @"photo":          @"photo",
 @"price":          @"price"
 }];

[eventMapping addConnectionForRelationship:@"farm" connectedBy:@"farmID"];