0
votes

I Have Created the Entity EY_REGION and added the attributes.To parse the RestKit value and to store the data in CoreData i have Created 2 Methods

(void)createRegionMappingWithStore:(RKManagedObjectStore *)managedObjectStore saveInDelegate:(AppDelegate *)appDelegate

(NSArray *)getRegionData

Just Am calling this method from my NewConnectionViewController.m.My Problem is,i can't able to Fetch the Data. What is the Problem? Here i have shown my code:

DataAccessHandler.m

@implementation DataAccessHandler

+(void)createRegionMappingWithStore:(RKManagedObjectStore *)managedObjectStore saveInDelegate:(AppDelegate *)appDelegate{

RKEntityMapping *regionMapping = [RKEntityMapping mappingForEntityForName:@"EY_Region" inManagedObjectStore:managedObjectStore];
regionMapping.identificationAttributes = @[@"regionId"];
[regionMapping addAttributeMappingsFromDictionary:@{ @"id" : @"regionId", @"name" : @"regionName", @"code" : @"regionCode",@"last_update":@"lastUpdatedDate",@"is_delete":@"isDelete"}];

RKResponseDescriptor *regionResponseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:regionMapping
                                             method:RKRequestMethodGET
                                        pathPattern:EY_REGION
                                            keyPath:@"data.data"
                                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)
 ];

[appDelegate createObjectManagerForurl:EY_BASE_URL andAddResponseDescriptor:regionResponseDescriptor];
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
}

+(NSArray *)getRegionData{

NSManagedObjectContext *context = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"EY_Region"];

NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"regionId" ascending:YES];
fetchRequest.sortDescriptors = @[descriptor];

NSError *error = nil;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
NSLog(@"fetched objects is: %@",fetchedObjects);
NSLog(@"size is: %lu",[fetchedObjects count]);
return fetchedObjects;
}

NewConnectionViewController.m

#import "NewConnectionViewController.h"
@implementation NewConnectionViewController

-(void)viewDidLoad
{

[super viewDidLoad];
[DataAccessHandler createConnectionMappingWithStore:[self managedObjectStore] saveInDelegate:[self appDelegate]];
[self requestConnectionData];
}

The Error am getting is,

NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: The representation inputted to the mapper was found to contain nested object representations at the following key paths: Address, Circle, ConnectionNumber, Distribution, Load, MeterNo, Name, Phase, Region, Section, ServiceNo, ServiceStatus, usage This likely indicates that you have misconfigured the key paths for your mappings., NSLocalizedDescription=No mappable object representations were found at the key paths searched., keyPath=null}}}

1

1 Answers

0
votes

First your request (which you haven't shown the code for) is asynchronous so it won't have completed when you query core data. Consider using a fetched results controller instead of an array so you get an update when new data is added.

Second, your request URL (EY_BASE_URL) and the path pattern (EY_REGION) (neither of which you've given details for) need to match up so that the path pattern is the section of the request URL that is not included in the base URL of the object manager.

Third, the error says keyPath=null but your response descriptor code says keyPath:@"data.data" so there is some mismatch between the code you show and what's actually running.

Fourth data.data, or even data is not listed in the key paths in the error message. You need to verify your key path against what you expect in the response and include in the key path only those keys you need to drill into to find the real data you want to map.

So, there are a number of things potentially wrong that you need to check through.