-
Notifications
You must be signed in to change notification settings - Fork 109
Protocols
You are here: Home → Documentation → Mac information page → Sc21 → Protocols
For the uninitiated: A protocol specifies a collection of methods that have to be implemented by a class to "conform" to that protocol.
Protocols are a way of defining data types without having to use inheritance: instead of requiring an argument to be of a certain type (derived from a certain class), you require it to be able to respond to certain messages - "any object that can do X and Y".
Protocols are very widely used in Objective-C. For an example of protocol usage in Sc21, see the SCDrawable, SCView, and SCController source code.
Protocol conformance is declared like this (SCView conforms to the SCDrawable protocol):
@interface SCView <SCDrawable>
The data type would then be id<SCDrawable>, used like this:
- (void)setDrawable:(id<SCDrawable>)newdrawable;