ios - Get objects from RKMappingResult -


how manage objects of specific type rkmappingresult? need establish relationship mapped data in rkmappingresults existing object.

i have tried:

[self getobjectsatpath:[nsstring stringwithformat:@"%@%@", baseurl restaurant.remoteid.stringvalue] parameters:nil success:^(rkobjectrequestoperation *operation, rkmappingresult *mappingresult) {           if (!mappingresult.array  || !mappingresult.array.count) {             dispatch_async(dispatch_get_main_queue(), ^{                   nserror *error = [self requestfailed];                 if (block) {                     block(nil, error);                 }              }) ;         } else {             __block bool done = no;             [[[coredatamanager sharedinstance] backgroundmanagedobjectcontext] performblockandwait:^{                 (menu *menu in mappingresult.array) {                     [restaurant addmenuobject:menu];                 }                  (tableids *tableid in mappingresult.array) {                                       [restaurant addtableidsobject:tableid];                      nslog(@"%@", tableid);                 }                   [[coredatamanager sharedinstance] savebackgroundcontext];                 done = yes;              }];             if (done) {                 dispatch_async(dispatch_get_main_queue(), ^{                      if (block) {                         block(mappingresult, nil);                     }                 });             }           }        } failure:^(rkobjectrequestoperation *operation, nserror *error) {          dispatch_async(dispatch_get_main_queue(), ^{              if (block) {                 block(nil, error);             }          }) ;     }]; 

in loop try 2 type of objects has been mapped, reason seems can't find difference between tableid , menu. menus added tableid crashes app.

what recieve when example nslog tableids:

<menu: 0x20e4dda0> (entity: menu; id: 0xf19eec0 <x-coredata://9f31f549-be4d-434c-935f-f689839989f2/menu/p39> ; data: { ...... 

how can correct objects , establish relationships correctly?

the success block called on main thread don't need switches or background contexts.

if going use background context, shouldn't directly using returned managed objects - need each managed objects id , in other context...

the mappingresult can return array , dictionary, dictionary keys key paths of response descriptors created objects. so, if have multiple response descriptors different key paths should use dictionary instead.

if can't need filter items process them. setting class type in fast enumeration won't (that black magic), need yourself:

for (nsmanagedobject *object in mappingresult.array) {     if ([object iskindofclass:[menu class]]) {         [restaurant addmenuobject:(menu *)menu];     } else if ([object iskindofclass:[tableids class]]) {         [restaurant addtableidsobject:(tableids *)tableid];     } } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -