- Inherits from:
- none (NSProxy is a root class)
- Conforms to:
- NSObject
Declared in:
- Foundation/NSProxy.h
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, NSDistantObject) 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 forwardInvocation: and methodSignatureForSelector: methods to handle messages that it doesn't implement itself. A subclass's implementation of forwardInvocation: 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. methodSignatureForSelector: 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 NSMethodSignature accordingly. See the NSDistantObject, NSInvocation, and NSMethodSignature class specifications for more information.
NSObject
- - autorelease
- - class
- - conformsToProtocol:
- - description
- - hash
- - isEqual:
- - isKindOfClass:
- - isMemberOfClass:
- - isProxy
- - performSelector:
- - performSelector:withObject:
- - performSelector:withObject:withObject:
- - release
- - respondsToSelector:
- - retain
- - retainCount
- - self
- - superclass
- - zone
- Creating instances
- + alloc
- + allocWithZone:
- Deallocating instances
- - dealloc
- Handling unimplemented methods
- - forwardInvocation:
- - methodSignatureForSelector:
- Getting a description
- - description
+ (id)alloc
+ (id)allocWithZone:(NSZone
*)zone
+ (Class)class
See Also: + class (NSObject), - class (NSObject protocol)
+ (void)load
load is usually invoked before initialize. It is usually the very first method sent to the class, although this isn't guaranteed. The order in which classes are loaded is also not guaranteed, to the point that superclasses aren't even guaranteed to be loaded before all of their subclasses. Because you can't rely on other classes being loaded at the point when your class is sent a load message, you should be extremely careful when messaging other classes from within your load method.
WARNINGDue to the amount of uncertainty about the environment at the point that load is invoked, you should avoid using load whenever possible. All class-specific initialization should be done in the class's initialize method.
See Also: + load (NSObject)
+ (BOOL)respondsToSelector:(SEL)aSelector
- (void)dealloc
- (NSString *)description
- (void)forwardInvocation:(NSInvocation
*)anInvocation
For example, if your proxy merely forwards messages to an instance variable named realObject, it can implement forwardInvocation: like this:
- (void)forwardInvocation:(NSInvocation *)anInvocation { [anInvocation setTarget:realObject]; [anInvocation invoke]; return; }
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
For example, if your proxy merely forwards messages to an instance variable named realObject, it can implement methodSignatureForSelector: like this:
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector { return [realObject methodSignatureForSelector:aSelector]; }
See Also: - methodSignatureForSelector: (NSObject)