What does <> mean / represent in class interface?
I'm sure I read this somewhere, Can anyone tell me> represent in the following interface?
@interface GameFinder : NSObject <NSNetServiceBrowserDelegate> @end
is the NSObject receiving <NSNetServiceBrowserDelegate>
?
EDIT
One thing that confuses me ...
in the example I have. The interface shows NSNetServiceBrowserDelegate
@interface ITunesFinder : NSObject <NSNetServiceBrowserDelegate> @end
but the implementation shows netServiceBrowser are they the same?
@implementation ITunesFinder -(void) netServiceBrowser: (NSNetServiceBrowser *) browser didFindService: (NSNetService *) service moreComing: (BOOL) moreComing {
Gary
source share
Angle brackets denote protocols that this class meets. The Protocols section contains information on the Objective-C Wikipedia article that may help you clarify a few things. Protocols contain both required and optional procedures that your class can provide. In the latter case, if the subroutine is not implemented by your class, the default implementation / behavior is used instead.
source share
The angle brackets in an interface declaration denote an Objective-C list protocols
that implements the interface. In this case, it GameFinder
complies with the protocol NSNetServiceBrowserDelegate
. The Objective-C Language Reference has a complete section on protocols (and this is a reference you should keep in general while learning Objective-C). Basically, a protocol is an interface that describes the methods that a class must implement to conform to that protocol. Classe interfaces can declare, using angle bracket notation, that they conform to (implement) the protocol. The compiler checks for protocol compliance if you provide protocol information in type declarations:
@interface Foo <Bar> ... - (void)methodRequiringBar:(id<Bar>)arg; @end @interface Foo2 <Baz> ... @end id<Bar> v = [[Foo alloc] init]; //OK id<Baz> v = [[Foo alloc] init]; //warning [v methodRequiringBar:[[Foo2 alloc] init]]; //warning
The compiler will also warn you if the class interface declares conformance to a protocol, but not all required methods in that protocol are implemented by the class implementation:
@protocol Bar @required - (void)requiredMethod; @optional - (void)optionalMethod; @end @interface Foo <Bar> ... @end @implementation Foo - (void)optionalMethod { ... } @end
will give a warning that the protocol is Bar
not fully implemented.
source share