Is there any significant difference in performance when you call
[someObject performSelector:@selector(testMethod:) withObject:anotherObject];
vs
[someObject testMethod:anotherObject];
?
Sends a specified message to the receiver and returns the result of the message.
Swift is statically typed so the performSelector: methods are to fall by the wayside. Instead, use GCD to dispatch a suitable block to the relevant queue — in this case it'll presumably be the main queue since it looks like you're doing UIKit work.
The first causes an extra call to objc_msgSend() that isn't necessary in the second case.
The performance difference is unlikely to remotely matter unless you are calling said method as quickly as you possibly can many 10s of thousands of times and you aren't doing any significant work in testMethod:
.
I.e. don't worry about it unless you measure an actual performance problem.
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