Swemoph Swemoph - 11 months ago 69
Objective-C Question

NSNumber * to NSString * from CoreData

I currently have an

of objects that have come from CoreData - one of the properties (named
) is an
. I'm doing some comparisons in my code and need to convert this
to a

I've got this to work, however I am wondering what the difference between these two pieces of code is:

NSNumber * arrayValueNum = [coreArray[i] identifier];
NSString * arrayValue = [arrayValueNum stringValue];


NSString * test = [[coreArray[i] identifier] stringValue];

For some reason this second snippet will not compile, and the first one will.


no visible @interface for 'NSString' declares the selector 'stringValue'

Aren't they the same, except that the
NSNumber *
value is in the braces instead of being in it's own variable?

Answer Source

Compiler is saying that [coreArray[i] identifier] is already NSString and NSString doesn't have method stringValue, so try to write like this.

NSString *test = [NSString stringWithFormat:@"%@",[coreArray[i] identifier]];