You need to map the entity records to each relationship. If you generate the managed object subclasses for these entities you can see few methods for each relationship. you need to use that to map the entity records.
id connection;
for(connection in connections)
{
//Get the JSON values
NSString *contentSystemID = [connection objectForKey:@"contentSystemId"];
NSString *contentSystemName = [connection objectForKey:@"name"];
NSString *logoUrl = [connection objectForKey:@"logo"];
NSNumber *unreadCount = [connection objectForKey:@"unread_count"];
FCConnection *connectionEntity = [FCConnection MR_createEntity];
connectionEntity.contentSystemID = contentSystemID;
connectionEntity.contentSystemName = contentSystemName;
connectionEntity.logoUrl = logoUrl;
connectionEntity.unreadCount = unreadCount;
id categories = [connection objectForKey:@"categories"];
NSMutableArray *categoryArray = [NSMutableArray array];
for (id cat in categories)
{
NSString *title = [cat valueForKey:@"name"];
NSString *unreadCount = [cat valueForKey:@"unread_count"];
id items = [cat objectForKey:@"items"];
BaseTopic *baseEntity = [BaseTopic MR_createEntity];
baseEntity.title = title;
FCCatgory *category = [FCCatgory MR_createEntity];
NSMutableArray *itemArray = [NSMutableArray array];
for (id item in items)
{
NSNumber *isRead = [item valueForKey:@"unread"];
NSString *title = [item valueForKey:@"title"];
NSString *link = [item valueForKey:@"link"];
NSString *systemID = [item valueForKey:@"itemId"];
Article *article = [Article MR_createEntity];
article.link = link;
article.systemID = systemID;
article.isRead = isRead;
article.category = category;
[itemArray addObject:article];
}
[category addArticles:[NSSet setWithArray:itemArray]]; // mapping the items to category
category.connection = connectionEntity;
[categoryArray addObject:category];
}
[connectionEntity addCategories:[NSSet setWithArray:categoryArray]]; // mapping the items to connection entity
}
Hope this will help you