Search code examples
iosobjective-ccastingnsstringnsobject

How to convert iOS id type which holds int to NSString?


I have an id which holds an int. I need to cast it to an NSString and append it to another NSString.

I've trued different approaches but I have different type of errors. My confusion is that int is not an object type.

My code is:

NSString *str = [dict objectForKey:[NSNumber numberWithLongLong:ID]];

In this case I have (int) 1000.

When I try to append it to NSString I get an exception.

How can I properly cast from an id, which holds int, to NSString ?


Solution

  • NSString *str = [[dict objectForKey:[NSNumber numberWithLongLong:ID]] stringValue];