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}}}