Next Page > Hide TOC

NSProtocolChecker Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in Mac OS X v10.0 and later.
Companion guide
Declared in
NSProtocolChecker.h

Overview

The NSProtocolChecker class defines an object that restricts the messages that can be sent to another object (referred to as the checker’s delegate). This fact can be particularly useful when an object with many methods, only a few of which ought to be remotely accessible, is made available using the distributed objects system.

A protocol checker acts as a kind of proxy; when it receives a message that is in its designated protocol, it forwards the message to its target and consequently appears to be the target object itself. However, when it receives a message not in its protocol, it raises an NSInvalidArgumentException to indicate that the message isn’t allowed, whether or not the target object implements the method.

Typically, an object that is to be distributed (yet must restrict messages) creates an NSProtocolChecker for itself and returns the checker rather than returning itself in response to any messages. The object might also register the checker as the root object of an NSConnection.

The object should be careful about vending references to self—the protocol checker will convert a return value of self to indicate the checker rather than the object for any messages forwarded by the checker, but direct references to the object (bypassing the checker) could be passed around by other objects.

Tasks

Creating a Checker

Getting Information

Class Methods

protocolCheckerWithTarget:protocol:

Allocates and initializes an NSProtocolChecker instance that will forward any messages in aProtocol to anObject, the protocol checker’s target.

+ (id)protocolCheckerWithTarget:(NSObject *)anObject protocol:(Protocol *)aProtocol

Discussion

Thus, the checker can be vended in lieu of anObject to restrict the messages that can be sent to anObject. Returns the new instance.

Availability
Declared In
NSProtocolChecker.h

Instance Methods

initWithTarget:protocol:

Initializes a newly allocated NSProtocolChecker instance that will forward any messages in aProtocol to anObject, the protocol checker’s target.

- (id)initWithTarget:(NSObject *)anObject protocol:(Protocol *)aProtocol

Discussion

Thus, the checker can be vended in lieu of anObject to restrict the messages that can be sent to anObject. If anObject is allowed to be freed or dereferenced by clients, the free method should be included in aProtocol.

Availability
Declared In
NSProtocolChecker.h

protocol

Returns the protocol object the receiver uses.

- (Protocol *)protocol

Availability
Declared In
NSProtocolChecker.h

target

Returns the target of the receiver.

- (NSObject *)target

Availability
Declared In
NSProtocolChecker.h

Next Page > Hide TOC


© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-05-23)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.