Formal protocols are declared using the @protocol directive:
@protocol ProtocolName < protocol list > |
method declarations |
@end |
The list of incorporated protocols and the method declarations are optional. The protocol must import the header files that declare any protocols it incorporates.
You can create a forward reference to a protocol using the @protocol directive in the following manner:
@protocol ProtocolName; |
Within source code, protocols are referred to using the similar @protocol() directive, where the parentheses enclose the protocol name.
Protocol names listed within angle brackets (<...>) are used to do three different things:
In a protocol declaration, to incorporate other protocols (as shown earlier)
In a class or category declaration, to adopt the protocol (as shown in “Classes” and “Categories”)
In a type specification, to limit the type to objects that conform to the protocol
Within protocol declarations, these type qualifiers support remote messaging:
Type Qualifier | Definition |
|---|---|
The method is for asynchronous messages and has no valid return type. | |
The argument passes information to the remote receiver. | |
The argument gets information returned by reference. | |
The argument both passes information and gets information. | |
A copy of the object, not a proxy, should be passed or returned. | |
A reference to the object, not a copy, should be passed or returned. |
Last updated: 2008-02-05