Mapping to one CoreData attribute from a collection of elements using RestKit RKDynamicMapping -
i trying map 1 coredata attribute following json:
{ "products": [ { "stock": { "instock": true, "instockbeforemaxadvanceorderingdate": false }, "url": "xxxxxxxxxxx", "manufacturer": "demo", "images": [ { "format": "thumbnail", "imagetype": "primary", "url": "/imageurl/xx.jpg" }, { "format": "thumbnailgrid", "imagetype": "primary", "url": "/imageurl/xxx.jpg" } ], "productfees": [ [ "empty", "0.0" ] ], "name": "demo product" } ]
}
i trying extract thumbnailgrid image url images collection. in responses have lot of times collection returned interested in 1 field. can setup relationships in coredata , have no problems, because know match 1 resource prefer store in 1 attribute rather relationship.
my product coredata entity has thumbnailimageurl attribute.
my product entity mapping:
rkentitymapping *mapping = [rkentitymapping mappingforentityforname:@"product" inmanagedobjectstore:_managedobjectstore]; [mapping addattributemappingsfromdictionary:@{ @"stock.instock":@"instock", @"stock.instockbeforemaxadvanceorderingdate":@"instockbeforemaxadvanceorderingdate", @"url":@"url", @"manufacturer": @"manufacturer", @"manufacturername":@"manufacturername", @"name":@"name", }]; rkdynamicmapping *dynamicmapping = [rkdynamicmapping new]; [mapping addpropertymapping:[rkrelationshipmapping relationshipmappingfromkeypath:@"images" tokeypath:@"thumbnailimageurl" withmapping:dynamicmapping]]; [dynamicmapping setobjectmappingforrepresentationblock:^rkobjectmapping *(id representation) { if ([[representation objectforkey:@"format"] isequaltostring:@"thumbnailgrid"]) { return ???; } return nil; }];
i not sure return dynamic mapper when match occurs. shall create rkentitymapping instance map same "product" entity , map url thumbnailimageurl?
also passible add somehow dynamic mapper attribute rather relationship?
thanks,
csaba
i'd store collection , filter out later. or, add method managed object subclass called set collection , filtering there (setting filter result actual attribute). trying restkit kind of filter hard (i'm not sure can it).
Comments
Post a Comment