I have mapping like this:
RKObjectMapping *pageMapping = [RKEntityMapping mappingForEntityForName:#"Page" inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[pageMapping addAttributeMappingsFromArray:#[ #"rows, columns", #"header", #"size", #"backgroundColor" ]];
RKObjectMapping *objectMapping = [RKEntityMapping mappingForEntityForName:#"Object" inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[objectMapping addAttributeMappingsFromArray:#[ #"content", #"crop", #"fontName", #"fontSize", #"height", #"width",
#"paddingLeft", #"paddingTop", #"paddingRight", #"paddingBottom", #"src", #"textColor", #"type", #"url", #"posX", #"posY" ]];
[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"objects" toKeyPath:#"objects" withMapping:pageMapping]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:pageMapping pathPattern:nil keyPath:#"pages" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];
[[RKObjectManager sharedManager] getObjectsAtPath:[magazine contentPath]
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self sortPageResult];
Page *page = (Page *)[self.pagesFetchedResultController objectAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSLog(#"%d", [[page objects] count]);
//[self changeStatusToDownloaded:[magazine magazineID]];
[self.collectionView reloadData];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
[self displayError];
NSLog(#"Product error: %#", [error localizedDescription]);
[self.collectionView reloadData];
}];
And I've got a problem with mapping. I clearly map "page" object, but I can't map "object". When I try it I get something like this:
Relationship 'objects' fault on managed object (0x1d8b57a0) <Page: 0x1d8b57a0> (entity: Page; id: 0x1d8b0740 <x-coredata://30A44191-D972-4222-88DF-539C2875F293/Page/p1> ; data: {
backgroundColor = FFFFFF;
columns = 0;
content = nil;
header = 1;
link = nil;
magazine = nil;
margin = 0;
objects = "<relationship fault: 0x1d8aea40 'objects'>";
pageID = nil;
rows = 0;
size = 1;
})
Thx for reply!
New progress
I've changed:
[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"objects" toKeyPath:#"objects" withMapping:pageMapping]];
instead:
[pageMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"items" toKeyPath:#"items" withMapping:itemMapping]];
Now is mapping right, but mapping causing duplicating "object" entities. There's only one object, which is remaking again and again :/
Related
Am i doing something weired here ?
my categories get downloaded and mapped,
product also get downloaded and mapped as logging is saying,
but my products are empty under each category,
thnx!
{
"productsCategories" : [
{
"product" : [
{
"price" : 3.99,
"title" : "Product A"
},
{
"price" : 3.99,
"title" : "ProductB "
}
],
"categoryTitle" : “a category“
}
]
}
RKObjectMapping *productCategoryMapping = [RKObjectMapping mappingForClass:[ProductCategory class]];
[productCategoryMapping addAttributeMappingsFromDictionary:#{
#"categoryTitle": #"tit"
}];
RKObjectMapping* productMapping = [RKObjectMapping mappingForClass:[Product class] ];
[productMapping addAttributeMappingsFromDictionary:#{
#"title": #"tit",
#"price": #"prc"
}];
[productCategoryMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"product"
toKeyPath:#"product"
withMapping:productMapping]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:productCategoryMapping method:RKRequestMethodPOST pathPattern:#"productByCategory" keyPath:#"productsCategories" statusCodes:[NSIndexSet indexSetWithIndex:200]];
NSURL *url=[NSURL URLWithString:#"http://www.example.com/REST/v2/"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:url];
[manager addResponseDescriptor:responseDescriptor];
NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionary];
[mutableParameters setValue:#"1" forKey:#"id"];
[manager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:productCategoryMapping method:RKRequestMethodPOST pathPattern:#"productByCategory" keyPath:#"productsCategories" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
[manager postObject:request path:#"productByCategory" parameters:mutableParameters success:^(RKObjectRequestOperation *operation, RKMappingResult *result){
self.productCategoryArr=result.array;
[self.tblDetails reloadData];
}failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(#"Operation failed with error: %#", error);
self.productCategoryArr=nil;
}];
the logging says objects are being mapped for each products but I only get
ProductCategory: 0x7bf53510
ProductCategory: 0x7be57f00
arrays and 0 objects in each
Assuming your ProductCategory class has
NSArray *Product
NSString * tit
Create a top level RKObjectMapping like,
RKObjectMapping * ProductCategoryResponseMapping = [RKObjectMapping mappingForClass: [ProductCategoryResponse class]];
[ProductCategoryResponseMapping addAttributeMappingsFromDictionary:#{
#"productsCategories": #"productsCategories"
}];
And create new class ProductCategoryResponse which should have
NSArray * productsCategories
Use ProductCategoryResponseMapping for Response descriptor.
Now your response will have array of productsCategories, each having array of Products and String tit.
I have 2 RKObjectManager that configured to use same managedObjectStore.
With the first RKObjectManager I fetch list of objects, and with the second RKObjectManager I want to add data to these objects.
But instead of updating existing objects, new ones are created.
What am I missing?
Here is my code:
RKEntityMapping* serverAppMapping = [RKEntityMapping mappingForEntityForName:#"COApp" inManagedObjectStore:[RKObjectManager coopsiManager].managedObjectStore];
[serverAppMapping addAttributeMappingsFromDictionary:#{
#"id": #"coID"
}];
serverAppMapping.identificationAttributes = #[ #"coID" ];
RKResponseDescriptor *serverAppResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:serverAppMapping method:RKRequestMethodGET pathPattern:#"/me/apps" keyPath:#"data.items" statusCodes:[NSIndexSet indexSetWithIndex:200]];
RKEntityMapping *appsMapping = [RKEntityMapping mappingForEntityForName:#"COApp" inManagedObjectStore:[RKObjectManager coopsiManager].managedObjectStore];
[appsMapping addAttributeMappingsFromDictionary:#{
#"trackName": #"name",
#"trackId": #"coID",
#"artworkUrl60":#"imageURL"}];
appsMapping.identificationAttributes = #[ #"coID" ];
[serverAppMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"app"
toKeyPath:#"app"
withMapping:appsMapping]];
// register mappings with the provider using a response descriptor
RKResponseDescriptor *appResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:appsMapping method:RKRequestMethodGET pathPattern:#"/th/lookup" keyPath:#"results" statusCodes:[NSIndexSet indexSetWithIndex:200]];
[[RKObjectManager appleManager] addResponseDescriptor:appResponseDescriptor];
[[RKObjectManager coopsiManager] addResponseDescriptor:serverAppResponseDescriptor];
NSString* access_token = [[COAuthManager sharedInstance] getUserAccessToken];
NSDictionary *queryParams;
queryParams = [NSDictionary dictionaryWithObjectsAndKeys:access_token, #"access_token", nil];
[[RKObjectManager coopsiManager] getObjectsAtPath:#"/me/apps" parameters:queryParams success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSOrderedSet* set = [NSOrderedSet orderedSetWithArray:mappingResult.array];
[me addNewApps:set];
self.objects = [me.newApps mutableCopy];
[self.delegate dataRefrashed];
NSManagedObjectContext *moc = [[RKObjectManager coopsiManager]managedObjectStore].persistentStoreManagedObjectContext;
NSError *error;
if (![moc save:&error]) {
NSLog(#"Fail");
}else{
NSLog(#"luda rest kit objetcs - %#",me.newApps);
}
for (COApp * app in self.objects) {
NSDictionary *queryParams = [NSDictionary dictionaryWithObjectsAndKeys:app.coID, #"id", nil];
[[RKObjectManager appleManager] getObjectsAtPath:[NSString stringWithFormat:#"/th/lookup"] parameters:queryParams success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
// app.app = mappingResult.array[0];
[self.delegate dataRefrashed];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
[self presentError:error];
}];
}
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
[self presentError:error];
}];
I'm trying to post new managed object with image to the web database as below and everything works fine for me except the little weird bug. When the managed object is uploaded successfully, 2 rows are added instead of one to the UITableView. When I'm refreshing the UITableView the one of the previously added UITableViewCell is populating with uploaded image. When I rebuild the app everything works fine. Previously added managed object is displayed correctly without duplication. Does anyone can take a look at my code and tell me what is the reason for that bug and how can I fix it? Let me know if you need more code.
-(void)postRequest{
NSEntityDescription *watchEntityDesc = [NSEntityDescription entityForName:#"Watches" inManagedObjectContext:[[RKObjectManager sharedManager]managedObjectStore].mainQueueManagedObjectContext];
Watches *watch = [[Watches alloc]initWithEntity:watchEntityDesc insertIntoManagedObjectContext:[[RKObjectManager sharedManager]managedObjectStore].mainQueueManagedObjectContext];
watch.phonewatchno = #"124512";
watch.latitude = [NSNumber numberWithDouble:-33.856870];
watch.longitude = [NSNumber numberWithDouble:151.215279];
NSEntityDescription *wearersEntityDesc = [NSEntityDescription entityForName:#"Wearers" inManagedObjectContext:[[RKObjectManager sharedManager]managedObjectStore].mainQueueManagedObjectContext];
Wearers *wearer = [[Wearers alloc]initWithEntity:wearersEntityDesc insertIntoManagedObjectContext:[[RKObjectManager sharedManager]managedObjectStore].mainQueueManagedObjectContext];
wearer.name =_nameTextField.text,
wearer.watches =[NSSet setWithObject:watch];
RKEntityMapping *watchesMapping = [RKEntityMapping mappingForEntityForName:#"Watches" inManagedObjectStore:[[EFDateModel sharedDataModel]objectStore]];
[watchesMapping addAttributeMappingsFromDictionary:#{
#"id": #"watch_id",
#"latitude":#"latitude",
#"longitude":#"longitude",
#"phonewatchno":#"phonewatchno",
}
];
[watchesMapping addConnectionForRelationship:#"wearer" connectedBy:#{
#"wearer_id":#"wearer_id"
}];
[watchesMapping setIdentificationAttributes:#[#"watch_id"]];
RKResponseDescriptor *responseDescr = [RKResponseDescriptor responseDescriptorWithMapping:watchesMapping method:RKRequestMethodPOST pathPattern:#"/watches.json" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager]addResponseDescriptor:responseDescr];
RKEntityMapping *wearersMapping = [RKEntityMapping mappingForEntityForName:#"Wearers" inManagedObjectStore:[[EFDateModel sharedDataModel] objectStore]];
[wearersMapping addAttributeMappingsFromDictionary:#{
#"id":#"wearer_id",
#"name":#"name",
}
];
wearersMapping.identificationAttributes = #[#"wearer_id"];
[wearersMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"watch" toKeyPath:#"watches" withMapping:watchesMapping]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:wearersMapping method:RKRequestMethodPOST pathPattern:#"/wearers.json" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[wearersMapping inverseMapping] objectClass:[Wearers class] rootKeyPath:nil method:RKRequestMethodPOST ];
[[RKObjectManager sharedManager]addResponseDescriptor:responseDescriptor];
[[RKObjectManager sharedManager]addRequestDescriptor:requestDescriptor];
[[RKObjectManager sharedManager]setRequestSerializationMIMEType:RKMIMETypeJSON];
[[RKObjectManager sharedManager]setAcceptHeaderWithMIMEType:#"application/json"];
UIImage *image =[UIImage imageWithCGImage:_wearerImage.CGImage scale:0.4 orientation:UIImageOrientationUp];
NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestWithObject:wearer method:RKRequestMethodPOST path:#"/wearers.json" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(image)
name:#"wearer_photo"
fileName:#"photo.png"
mimeType:#"image/png"];
}];
NSManagedObjectContext *moc =[[[RKObjectManager sharedManager]managedObjectStore]mainQueueManagedObjectContext];
RKManagedObjectRequestOperation *managedObjectOperation = [[RKObjectManager sharedManager]managedObjectRequestOperationWithRequest:request managedObjectContext:moc success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"Mapping result = %#",mappingResult.array);
[[RKObjectManager sharedManager]removeResponseDescriptor:responseDescriptor];
[[RKObjectManager sharedManager]removeRequestDescriptor:requestDescriptor];
[[NSNotificationCenter defaultCenter]
postNotificationName:#"ReloadTable"
object:self];
[self dismissViewControllerAnimated:YES completion:nil];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"Error : \n %#",error.description);
}];
[[RKObjectManager sharedManager] enqueueObjectRequestOperation:managedObjectOperation];
}
Cheers
Every time you are calling this method you are calling alloc]initWithEntity:... insertIntoManagedObjectContext: twice and creating two new entity instances. You should probably be passing an entity instance to this method that it uses and not creating any new instances.
Also, it is inefficient to keep creating new descriptors and adding and removing them. And if you try to make 2 requests at the same time you will get an error. Configure the object manager once before you first use it and then just use it repeatedly without reconfiguring.
I have a strange problem with Restkit. I'm doing the following:
-(void)doLogin:(NSString *)email andPassword:(NSString *)password OnCompletion:(myCompletion) compblock{
Mapper *mapper = [Mapper new];
RKManagedObjectStore *store = [[OffitelDataModel sharedDataModel] objectStore];
NSLog(#"store is %#",store);
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
RKObjectManager *objectManager = [mapper mapLogin];
NSString *deviceToken = [[NSUserDefaults standardUserDefaults]objectForKey:#"deviceToken"];
NSString *urlString = [NSString stringWithFormat:#"company-user/login/%#?email=%#&pwd=%#&ios_id=%#",apikey,email,password,deviceToken];
NSURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:urlString parameters:nil];
RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:context success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSError *error = nil;
BOOL success = [context save:&error];
if (!success) RKLogWarning(#"Failed saving managed object context: %#", error);
Data *data2 = [mappingResult.array objectAtIndex:0];
NSLog(#"MAPPING RESULT 0 = %#",[mappingResult.array objectAtIndex:0]);
NSLog(#"data status is %#",data2.webstatus);
int value = [data2.webstatus intValue];
if (value == 200){
Person *personObject = [mappingResult.array objectAtIndex:2];
NSString *name = [NSString stringWithFormat:#"%# %#",personObject.cu_first_name,personObject.cu_last_name];
NSDictionary *dictUser = [[NSDictionary alloc]initWithObjectsAndKeys:personObject.cu_id,#"personId",personObject.company.c_id,#"companyId",name,#"personName",personObject.cu_status_id,#"statusId", nil];
[[NSUserDefaults standardUserDefaults]setObject:dictUser forKey:#"user"];
[[NSUserDefaults standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:#"loggedIn"];
[[NSUserDefaults standardUserDefaults] synchronize];
compblock(YES);
}else{
//show validation
NSLog(#"ERROR");
}
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"ERROR");
}];
[objectManager enqueueObjectRequestOperation:operation];
}
En this is my mapping
-(RKObjectManager *)mapLogin{
RKObjectMapping* dataMapping = [RKObjectMapping mappingForClass:[Data class]];
[dataMapping addAttributeMappingsFromDictionary:#{
#"status": #"webstatus",
#"message": #"message",
#"text": #"text"
}];
RKEntityMapping* personMapping = [RKEntityMapping mappingForEntityForName:#"Person" inManagedObjectStore:managedObjectStore];
personMapping.identificationAttributes = #[#"cu_id"] ;
[personMapping addAttributeMappingsFromDictionary:#{
#"cu_id": #"cu_id",
#"cu_status_id": #"cu_status_id",
#"cu_company_id": #"cu_company_id",
#"cu_function_id": #"cu_function_id",
#"cu_department_id": #"cu_department_id",
#"cu_email": #"cu_email",
#"cu_first_name": #"cu_first_name",
#"cu_last_name": #"cu_last_name",
#"cu_phone_intern": #"cu_phone_intern",
#"cu_mobile_phone": #"cu_mobile_phone",
#"cu_street": #"cu_street",
#"cu_number": #"cu_number",
#"cu_bus": #"cu_bus",
#"cu_postalcode": #"cu_postalcode",
#"cu_location": #"cu_location",
#"cu_country": #"cu_country",
#"cu_birthdate": #"cu_birthdate",
#"cu_picture": #"cu_picture",
#"cu_comment": #"cu_comment",
#"cu_ison_reminder_email": #"cu_ison_reminder_email",
#"cu_ison_reminder_app": #"cu_ison_reminder_app",
#"cu_ison_reminder_web": #"cu_ison_reminder_web",
#"cu_first_use": #"cu_first_use"
}];
RKEntityMapping* functionMapping = [RKEntityMapping mappingForEntityForName:#"Function" inManagedObjectStore:managedObjectStore];
functionMapping.identificationAttributes = #[#"cf_id"] ;
[functionMapping addAttributeMappingsFromDictionary:#{
#"cf_id": #"cf_id",
#"cf_name":#"cf_name"
}];
RKEntityMapping* departmentMapping = [RKEntityMapping mappingForEntityForName:#"Department" inManagedObjectStore:managedObjectStore];
departmentMapping.identificationAttributes = #[#"cd_id"] ;
[departmentMapping addAttributeMappingsFromDictionary:#{
#"cd_id": #"cd_id",
#"cd_name":#"cd_name"
}];
RKEntityMapping* companyMapping = [RKEntityMapping mappingForEntityForName:#"Company" inManagedObjectStore:managedObjectStore];
companyMapping.identificationAttributes = #[#"c_id"] ;
[companyMapping addAttributeMappingsFromDictionary:#{
#"c_id": #"c_id",
#"c_name":#"c_name",
#"c_phone":#"c_phone",
#"c_fax":#"c_fax",
#"c_website":#"c_website"
}];
RKEntityMapping* statusMapping = [RKEntityMapping mappingForEntityForName:#"Status" inManagedObjectStore:managedObjectStore];
statusMapping.identificationAttributes = #[#"cs_id"] ;
[statusMapping addAttributeMappingsFromDictionary:#{
#"cs_id": #"cs_id",
#"cs_company_id":#"cs_company_id",
#"cs_name":#"cs_name",
#"cs_default":#"cs_default",
#"cs_image":#"cs_image"
}];
RKRelationshipMapping* relationFunctionMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:#"function"toKeyPath:#"function"withMapping:functionMapping];
RKRelationshipMapping* relationDepartmentMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:#"department"toKeyPath:#"department"withMapping:departmentMapping];
RKRelationshipMapping* relationCompanyMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:#"company"toKeyPath:#"company"withMapping:companyMapping];
RKRelationshipMapping* relationStatusMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:#"statuses"toKeyPath:#"status"withMapping:statusMapping];
[personMapping addPropertyMapping:relationFunctionMapping];
[personMapping addPropertyMapping:relationDepartmentMapping];
[personMapping addPropertyMapping:relationCompanyMapping];
[companyMapping addPropertyMapping:relationStatusMapping];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dataMapping
pathPattern:nil
keyPath:#"data" statusCodes:[NSIndexSet indexSetWithIndex:200]];
RKResponseDescriptor *responseDescriptor2 = [RKResponseDescriptor responseDescriptorWithMapping:personMapping
pathPattern:nil
keyPath:#"data.user"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
RKResponseDescriptor *responseDescriptor3 = [RKResponseDescriptor responseDescriptorWithMapping:companyMapping
pathPattern:nil
keyPath:#"data.user.company"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
NSArray *arrResponsDescriptor = [[NSArray alloc]initWithObjects:responseDescriptor,responseDescriptor2,responseDescriptor3, nil];
[objectManager addResponseDescriptorsFromArray:arrResponsDescriptor];
return objectManager;
}
The strange this is that on most phones it all works correct but only on 64-bit devices are going wrong.
When I look at this NSLog
NSLog(#"MAPPING RESULT 0 = %#",[mappingResult.array objectAtIndex:0]);
I see that in the not-64-bit devices it returns the Data class object. And thats oké. But in the 64-bit devices it returns the Company-object and that's not ok !
Can somebody help me with this ?
Kind regards
You have multiple response descriptors each with a nil path pattern, so they will always be applied to any response. RestKit does not guarantee the order in which they will be called. It also doesn't guarantee the order of the contents of mappingResult.array.
You should be using your key paths on the response descriptors to access the results of each descriptor. The mappingResult also offers you a dictionary (instead of array) where you can use the response descriptor key path to access the associated results. Use that to separate the Data results from the Company results.
RestKitObjectMapping Array off null objects
I want to map CapitalImage object in Capital images object property.
//------------------------ The mapping I try to
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class]
forMIMEType:#"text/html"];
RKObjectMapping *CapitalImageMap = [RKObjectMapping mappingForClass:[CapitalImage class]];
[CapitalImageMap addAttributeMappingsFromDictionary:#{
#"src": #"src"
}];
RKObjectMapping *CapitalMap = [RKObjectMapping mappingForClass:[Capital class]];
[CapitalMap addAttributeMappingsFromDictionary:#{
#"name": #"name",
#"text": #"text"
}];
[CapitalMap addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"images" toKeyPath:#"images" withMapping:CapitalImageMap]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:CapitalMap
method:RKRequestMethodAny
pathPattern:nil
keyPath:nil
statusCodes:statusCodes];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.a10073.de4.dp10.ru/icapitals/capital.php"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:#[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
Capital *article = [result firstObject];
NSLog(#"Mapped the article: %# , %#", article.name,article.images.description);
} failure:^(RKObjectRequestOperation *operation, NSError *error) { NSLog(#"Failed with error: %#", [error localizedDescription]); }];
[operation start];
I get this result
2013-09-27 23:20:49.028 iCapitals v2[5099:c07] Mapped the article: London , (
(null),
(null),
(null),
)
LOGS - http://www.a10073.de4.dp10.ru/icapitals/consoleresult.txt
Please check the code and tell what i do wrong, Thanks!!!
Your mappings look correct. The log shows the mapping proceeding correctly. The issue appears to be with the CapitalImage class. Why is it giving a nil description? It could be that that is the only problem. So your log of the array is a list of nil, but the objects do exist.
Try logging the src of each objects. Are you seeing other issues? Did you implement the description method?