Use-case of `oneway void` in Objective-C?

eonil picture eonil · Mar 31, 2011 · Viewed 17.6k times · Source

I found a strange keyword in NSObject.h

- (oneway void)release;

I searched the web, and learned it relates to asynchronous message passing, which looks similar with Erlang's message passing.

It seems this can make many interesting things. What are some good use-cases of this keyword?

Answer

ughoavgfhw picture ughoavgfhw · Mar 31, 2011

oneway is used with the distributed objects API, which allows use of objective-c objects between different threads or applications. It tells the system that it should not block the calling thread until the method returns. Without it, the caller will block, even though the method's return type is void. Obviously, it is never used with anything other than void, as doing so would mean the method returns something, but the caller doesn't get it.

For more on distributed objects, see Cocoa Conceptual DistrObjects.