I got a question for mapping a nested array. On https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md there's an example for mapping nested objects.
But what do I have to do, if the nested object is an array of objects, for example the JSON looks like:
{ "articles": [
{ "title": "RestKit Object Mapping Intro",
"body": "This article details how to use RestKit object mapping...",
"author": [{
"name": "Blake Watters",
"email": "[email protected]"
},
{
"name": "abc",
"email": "emailaddress"
}]
"publication_date": "7/4/2011"
}]
}
How should my classes look like, for getting an array of Authors? Thats the code from the example:
@interface Author : NSObject
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSString* email;
@end
@interface Article : NSObject
@property (nonatomic, retain) NSString* title;
@property (nonatomic, retain) NSString* body;
@property (nonatomic, retain) Author* author; // should be an array of Author-Objects
@property (nonatomic, retain) NSDate* publicationDate;
@end
How can I tell Restkit, that theres an Array of Authors and if I am changing the class of the author Attribute in Article to NSArray, how does Restkit knows, that in this NSArray should be Author-Objects...??
I am using RKObjectMapping to map Objects from JSON to Objective-c and vice versa.