Reputation: 107
I downloaded the source code for an application called adium, because I wanted to learn cocoa better by scrutinizing other people's code, but there is something very confusing to me in this interface:
@interface AIAdium : NSObject <AIAdium, SUVersionComparison> {
@private
IBOutlet NSObject <AIMenuController> *menuController;
IBOutlet NSObject <AIInterfaceController> *interfaceController;
IBOutlet SUUpdater *updater;
NSObject <AIAccountController> *accountController;
NSObject <AIChatController> *chatController;
NSObject <AIContactController> *contactController;
NSObject <AIContentController> *contentController;...
It goes on like this. What I don't understand is how NSObjects are conforming to protocols like AIAccountController. I thought you had to implement the methods defined in the interface of a protocol to conform to it, but how could NSObject be doing that?
Upvotes: 0
Views: 48
Reputation: 318794
That's not what those lines mean. Example:
NSObject <AIAccountController> *accountController;
What this means is that the accountController
ivar is a pointer to any NSObject
derived class that also conforms to the AIAccountController
protocol.
Since NSObject
is the root class of most other classes, this basically means any custom class that conforms to the protocol can be assigned to the ivar.
Nothing about the line has any bearing on NSObject
itself.
What the author of this code should have used was:
id<AIAccountController> accountController;
Upvotes: 3