Objective C: uint32_t stored as String, need to read as uint32_t
I am storing color values in a database for an iPad app that needs a legend with colors in it. Each entry has it's own color value, derived from a hex value. Basically, my colors all look like this: 0X######. I have functions that can take this value, as a uint32_t, and turn it into the color I need. However, I store the value as a String.
What I need to do is convert this string to a uint32_t. I need "0X######" to equal 0X######, if that makes sense. I know this might not be possible, in which case I'll have to find another开发者_高级运维 solution.
You can use NSScanner
for this.
NSScanner * scanner = [NSScanner scannerWithString:@"0XAABBCC"];
uint32_t val;
[scanner scanHexLongLong:&val];
I got this code this will worked in my code,
NSScanner * scannered = [NSScanner scannerWithString:colorHex];
uint32_t scanedVal;
[scannered scanHexLongLong:(unsigned long long *)&scanedVal];
NSLog(@"scanner _____%u",scanedVal);
精彩评论