What's different between selectors with same arguments type but different arguments sort?
I got these two selectors with same arguments type.
- (void)methodWithCallBack:(void(^)(void)) cb double:(double)value {
NSLog(@"%s %f", __PRETTY_FUNCTION__, value);
if (cb) {
cb();
}
}
- (void)methodWithDouble:(double)value callBack:(void(^)(void)) cb {
NSLog(@"%s %f", __PRETTY_FUNCTION__, value);
if (cb) {
cb();
}
}
But when performSelector:withObject:withObject: called with these selectors, I got different result.
[self performSelector:@selector(methodWithDouble:callBack:) withObject:@(2.5) withObject:[^(void){
NSLog(@"Test Call Back Double");
} copy]];
[self performSelector:@selector(methodWithCallBack:double:) withObject:[^(void){
NSLog(@"Test Call Back Double");
} copy] withObject:@(2.5)];
How does this happend? What does performSelector:withObject:withObject: really do?
I have no idea what @(2.5) is.
NSNumberliteral is @2.5. a double is non object andNSNumberis object. You should pass anNSNumber.On a second note: I feel weird that Apple created
performSelector:withObject:withObject:. A single "withObject" is suffice actually, you just pass anNSArraywith objects you want to pass to that.Eg.