I currently have an NSArray
of objects that have come from CoreData - one of the properties (named identifier
) is an NSNumber
. I'm doing some comparisons in my code and need to convert this NSNumber
to a NSString
.
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];
and
NSString * test = [[coreArray[i] identifier] stringValue];
For some reason this second snippet will not compile, and the first one will.
Error:
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?
您可以使用stringWithFormat
直接为此NSString
变量赋值。
NSString *test = [NSString stringWithFormat:@"%@",[coreArray[i] identifier]];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.