An abstract superclass defining an API for objects that act as stand-ins for other objects or for objects that don’t exist yet.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Typically, a message to a proxy is forwarded to the real object or causes the proxy to load (or transform itself into) the real object. Subclasses of
NSProxy can be used to implement transparent distributed messaging (for example,
NSDistant) or for lazy instantiation of objects that are expensive to create.
NSProxy implements the basic methods required of a root class, including those defined in the
NSObject protocol. However, as an abstract class it doesn’t provide an initialization method, and it raises an exception upon receiving any message it doesn’t respond to. A concrete subclass must therefore provide an initialization or creation method and override the
method methods to handle messages that it doesn’t implement itself. A subclass’s implementation of
forward should do whatever is needed to process the invocation, such as forwarding the invocation over the network or loading the real object and passing it the invocation.
method is required to provide argument type information for a given message; a subclass’s implementation should be able to determine the argument types for the messages it needs to forward and should construct an
NSMethod object accordingly. See the
NSMethod class specifications for more information.