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?
appendString
method. (In fact, it's hard to make heads or tails out of your code.) – Hot Licks May 14 at 18:13NSValueTransformer
subclass and put your existing logic into the-transformedValue:
method. – bdesham May 14 at 21:35NSValueTransformer
as I am not 100% on how they work. In this case I need a string from an Array of Arrays is that possible with a subclass of NSValueTransformer, could you explain more please – StuartM May 14 at 22:21