Can anyone tell me what the angle brackets "<…>" in an Obj-C class interface do? Like this… http://snipt.net/robhawkes/cocoa-class-interface
@interface MapMeViewController : UIViewController <CLLocationManagerDelegate,
MKReverseGeocoderDelegate, MKMapViewDelegate, UIAlertViewDelegate> { ... }
From my view they look like some sort of type declaration (considering my previous experience in PHP and JavaScript), like we're making sure MapMeViewController
is a CLLocationManagerDelegate
, MKReverseGeocoderDelegate
, MKMapViewDelegate
, or UIAlertViewDelegate
Documentation about the @interface syntax don't seem to mention this.
The angle brackets in a class interface definition indicates the protocols that your class is conforming to.
A protocol is almost like an interface in Java or C#, with the addition that methods in an Objective-C protocol can be optional.
Additionaly in Objective-C you can declare a variable, argument or instance variable to conform to several protocols as well. Example
In this case the class must be
NSObject
or a subclass (onlyNSProxy
and its subclasses would fail), and it must also conform to bothNSCoding
andUITableViewDelegate
protocols.In Java or C# this would only be possible by actually declaring said class.
The angle brackets indicate a protocol. They're analogous to interfaces in other languages.
Apple documentation reports the use of brackets; see The Objective-C Programming Language on the chapter 4, on "Adopting a Protocol".
You can also use them in code like a cast to tell the complier to expect an object that conforms to a particular protocol.