Is it possible to define an anonymous selector in Objective-C?

I would like to be able to define a built-in anonymous selector so that the selector is wherever the selector is needed as an argument.

Is this possible, or do I just need to suck it and define a method?

Background . In my iPhone application, I need to update my interface from another thread. For this, I use performSelectorOnMainThread:withObject:waitUntilDone: However, I would like to be able to get this functionality without defining another method.

+7
objective-c iphone anonymous-methods selector
source share
1 answer

Unfortunately not. The idea is consistent - the selector is the name. It's all. It does not define any functionality.

Objective-C did not have any anonymous function until recently, when blocks were introduced in Mac OS X. You can use them on iPhone through Plausible Blocks , but they are still not integrated into the API.

2014 update

This answer was correct in 2009, but Apple has long integrated blocks into iOS frameworks. They are used universally for callbacks and are widely used in the Grand Central Dispatch concurrency library.

+16
source share

All Articles