Reputation: 235
I'm not sure if the title is correct for what I need to do, but I simply need to take a literal NSString
string and make it a uint32_t
Basically this is what I'm wanting to do:
NSString *literal = @"0x0001234";
uint32_t = literal; // uint32_t = 0x0001234;
I tried using some casts but those just gave me errors, so how can I do this?
*I'm not too familiar with Obj-C, so not sure what I should be searching for exactly.
Upvotes: 0
Views: 391
Reputation: 114984
You can't use a simple assignment, even with a case, because NSString
and uint32
are completely different things.
You can use the NSScanner
scanHexInt
method. Note that this method can fail if the string isn't a valid hex string.
NSString *literal = @"0x0001234";
unsigned output = 0;
if ([[NSScanner scannerWithString:literal] scanHexInt:&output]) {
// Do something with output
} else {
// Unable to parse string
}
Upvotes: 1