I am trying to pass a hex value as an unsigned int to a method using a dynamic link. The value I pass as a parameter is getting corrupted somehow. What is happening?
- (void)callPerformSelector
{
NSNumber *argument = [NSNumber numberWithUnsignedInt:(unsigned int)0xFFFFFFFF];
SEL selector = NSSelectorFromString(@"testPerformSelector:");
NSLog(@"testPerformSelector object %@", argument);
[self performSelector:selector withObject:argument];
}
- (void)testPerformSelector:(unsigned int) arg1
{
NSLog(@"testPerformSelector unsigned int %u", arg1);
NSLog(@"testPerformSelector hex %X", arg1);
}
Output is:
testPerformSelector object 4294967295
testPerformSelector unsigned int 4294967283
testPerformSelector hex FFFFFFF3
Because it should be:
- (void)callPerformSelector
{
NSNumber *argument = @0xFFFFFFFF;
SEL selector = @selector(testPerformSelector:);
NSLog(@"testPerformSelector object %@", argument);
[self performSelector:selector withObject:argument];
}
- (void)testPerformSelector:(NSNumber *) arg1
{
NSLog(@"testPerformSelector unsigned int %u", arg1.unsignedIntValue);
}
unsigned int
and NSNumber *
is two different things
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With