I'd like to be able to define an inline anonymous selector that a selector wherever a selector is needed as an argument.
Is this possible, or do I have to just suck it up and define a method?
Background: In my iPhone application I need to update my UI from another thread. To do this I use performSelectorOnMainThread:withObject:waitUntilDone:
However, I'd like to be able to get this functionality without having to define a whole other method.
Unfortunately, no. The idea is self-contradictory — a selector is a name. That's all it is. It doesn't define any functionality.
Objective-C didn't have any kind of anonymous function until just recently when blocks were introduced into Mac OS X. It's possible to use them on the iPhone through Plausible Blocks, but they're still not integrated into the APIs there.
This answer was correct back in 2009, but by now Apple has integrated blocks very well into the iOS frameworks. They're used pretty pervasively for callbacks now and are heavily used in the Grand Central Dispatch concurrency library.
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