NSDistantObject is a concrete subclass of
NSProxy that defines proxies for objects in other applications or threads. When a distant object receives a message, in most cases it forwards the message through its
NSConnection object to the real object in another application, supplying the return value to the sender of the message if one is received, and propagating any exception back to the invoker of the method that raised it.
- macOS 10.0+
NSDistantObject adds two useful instance methods to those defined by
connectionForProxy returns the
NSConnection object that handles the receiver;
setProtocolForProxy: establishes the set of methods the real object is known to respond to, saving the network traffic required to determine the argument and return types the first time a particular selector is forwarded to the remote proxy.
There are two kinds of distant object: local proxies and remote proxies. A local proxy is created by an
NSConnection object the first time an object is sent to another application. It is used by the connection for bookkeeping purposes and should be considered private. The local proxy is transmitted over the network using the
NSCoding protocol to create the remote proxy, which is the object that the other application uses.
NSDistantObject defines methods for an
NSConnection object to create instances, but they’re intended only for subclasses to override—you should never invoke them directly. Use the
rootProxyForConnectionWithRegisteredName:host: method of
NSConnection, which sets up all the required state for an object-proxy pair.