Class: NSProxy

Inherits:
NSObject show all

Overview

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.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, format, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Object) alloc

Returns a new instance of the receiving class

Returns:

+ (Object) allocWithZone(zone)

Returns a new instance of the receiving class

Returns:

  • (Object)

    A new instance of the receiving class, as described in the NSObject class specification under the allocWithZone: class method.

+ (Class) class

Returns self (the class object).

Returns:

  • (Class)

    self. Because this is a class method, it returns the class object

+ (Boolean) respondsToSelector(aSelector)

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

Parameters:

  • aSelector (Symbol)

    A selector.

Returns:

  • (Boolean)

    YES if the receiving class responds to aSelector messages, otherwise NO.

Instance Method Details

- (Object) dealloc

Deallocates the memory occupied by the receiver. This method behaves as described in the NSObject class specification under the dealloc instance method.

Returns:

- (String) debugDescription

Returns an string containing the real class name and the id of the receiver as a hexadecimal number. This allows this method declared by the NSObject protocol to be implemented in developer classes without causing an issue to be flagged in the iOS and Mac app stores, where otherwise it might look like the developer is overriding a private method in the Foundation Kit.Implementation of this method is optional, so be sure to test for its existence before attempting to invoke it.

Returns:

  • (String)

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

- (String) description

Returns an NSString object containing the real class name and the id of the receiver as a hexadecimal number.

Returns:

  • (String)

    An NSString object containing the real class name and the id of the receiver as a hexadecimal number.

- (Object) finalize

The garbage collector invokes this method on the receiver before disposing of the memory it uses. This method behaves as described in the NSObject class specification under the finalize instance method. Note that a finalize method must be thread-safe.

Returns:

- (Object) forwardInvocation(anInvocation)

Passes a given invocation to the real object the proxy represents. NSProxy’s implementation merely raises NSInvalidArgumentException. Override this method in your subclass to handle anInvocation appropriately, at the very least by setting its return value.For example, if your proxy merely forwards messages to an instance variable named realObject, it can implement forwardInvocation: like this:

Parameters:

  • anInvocation (NSInvocation)

    The invocation to forward.

Returns:

- (NSMethodSignature) methodSignatureForSelector(aSelector)

Raises NSInvalidArgumentException. Override this method in your concrete subclass to return a proper NSMethodSignature object for the given selector and the class your proxy objects stand in for. Be sure to avoid an infinite loop when necessary by checking that aSelector isn’t the selector for this method itself and by not sending any message that might invoke this method.For example, if your proxy merely forwards messages to an instance variable named realObject, it can implement methodSignatureForSelector: like this:

Parameters:

  • aSelector (Symbol)

    The selector for which to return a method signature.

Returns: