I have to do some encoding and then assign the result to a label. Is there a more optimal (or concise) way to write this?

// encoding fix    
NSString *correctStringTitle = [NSString stringWithCString: [[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding] 
                                                  encoding: NSUTF8StringEncoding];

cell.titleLabel.text = [correctStringTitle capitalizedString];

1 Answer 1


Here is a marginally more concise solution:

cell.titleLabel.text = [NSString stringWithCString:[[item[@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding].capitalizedString;

If I had to do this more than once I would consider hiding this complexity in an NSString category like:

@interface NSString(Utils)

@implementation NSString(Utils)

     return [NSString stringWithCString:[self cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];


This will simplify your code to:

cell.titleLabel.text = ((NSString*)item[@"main_tag"]).stringWithLatinEncoding.capitalizedString;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.