The NSProtocolChecker and NSProxy classes provide message
filtering and forwarding capabilities. If you wish
to ensure at runtime that a given object will only be sent
messages in a certain protocol, you create an
NSProtocolChecker
instance with the
protocol and the object as arguments-
id versatileObject = [[ClassWithManyMethods alloc] init];
id narrowObject = [NSProtocolChecker protocolCheckerWithTarget: versatileObject
protocol: @protocol(SomeSpecificProtocol)];
return narrowObject;
This is often used in conjunction with distributed
objects to expose only a subset of an objects methods
to remote processes
- (id)
initWithTarget: (
NSObject*)anObject
protocol: (Protocol*)aProtocol;
Availability: OpenStep
Initializes a newly allocated NSProtocolChecker
instance that will forward any messages in the
aProtocol protocol to anObject,
its delegate. Thus, the checker can be vended in lieu
of anObject to restrict the messages that can
be sent to anObject. If any method in the
protocol returns anObject, the checker
will replace the returned value with itself rather
than the target object.
Returns the new
instance.