I may be making something incredibly simple incredibly complicated, but nothing I’ve tried so far seems to work.
I have NSStrings like @”BD8F60″ and I would like to turn them into ints like: r = 189, g = 143, b = 96.
Have found ways to convert hex values that are already ints into rgb ints, but am stuck on how to change the NSString with the letters in it into an int where the letters have been converted to their numerical counterparts. Apologize in advance if this is incredibly basic–I’m still learning this stuff at an incredibly basic level.
You need to parse the NSString and interpret the hex values.
You may do this in multiple ways, one being using an NSScanner
There are some other possibilities like splitting the string in 3 and scan the values separately (instead of doing bitwise shift and masking) but the idea remains the same.
Note: as
scanHexInt:documentation explains, this also works if your string is prefixed with0xlike@"0xBD8F60". Does not automatically work with strings prefixed by a hash like@"#BD8F60". Use a substring in this case.