I am using Mantle to parse some business JSON. At present we go through an array of JSON objects for the business categories with the following:
NSMutableString *stringCats = [[NSMutableString alloc] init];
for (NSArray *cats in business.yelpCategories)
{
NSString *category = [cats objectAtIndex:0];
if ([category length] > 0) {
if ([category hasSuffix:@"s"]) {
category = [category substringToIndex:[category length] - 1];
}
}
if (cats == business.yelpCategories.lastObject) {
[stringCats appendString:[NSString stringWithFormat:@"%@",category]];
} else {
[stringCats appendString:[NSString stringWithFormat:@"%@, ",category]];
}
}
searchResultCell.stringCategories.text = stringCats;
This loops through the array of categories removes the last letter if an 's' then appends the string into one string.
This is currently completed in the cellForRowAt..
and I feel like this is not the correct place to do this sort of work.
What I would like to do is parse this data into a string on the business model created with Mantle originally rather than complete this for each cell.
Question
How do I create a custom NSValueTransformer based on our current work above to transform the JSON array into a string on the model instead?