NSProxy is an abstract superclass defining an API for objects that act as stand-ins for other objects or for objects that don’t exist yet. 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​Object) 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 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 forward​Invocation(_:​) and method​Signature​For​Selector:​ methods to handle messages that it doesn’t implement itself. A subclass’s implementation of forward​Invocation(_:​) 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​Signature​For​Selector:​ 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​Signature object accordingly. See the NSDistant​Object, NSInvocation, and NSMethod​Signature class specifications for more information.


Creating Instances

class func alloc()

Returns a new instance of the receiving class

Finalizing an Object

func finalize()

The garbage collector invokes this method on the receiver before disposing of the memory it uses.

Handling Unimplemented Methods

func forward​Invocation(NSInvocation)

Passes a given invocation to the real object the proxy represents.

Introspecting a Proxy Class

class func responds(to:​ Selector)

Returns a Boolean value that indicates whether the receiving class responds to a given selector.

Describing a Proxy Class or Object

class func `class`()

Returns self (the class object).

var description:​ String

A string containing the real class name and the id of the receiver as a hexadecimal number.

var debug​Description:​ String

A string containing the real class name and the id of the receiver as a hexadecimal number.