Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the angle brackets "<…>" in an Obj-C class interface for?

Tags:

Can anyone tell me what the angle brackets <...> in an Objective-C class interface do? Like this one (from 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.

like image 686
robhawkes Avatar asked Dec 16 '09 11:12

robhawkes


People also ask

What is the purpose of angle brackets?

An angle bracket or angle brace or angle cleat is an L-shaped fastener used to join two parts generally at a 90 degree angle. It is typically made of metal but it can also be made of wood or plastic. The metallic angle brackets feature holes in them for screws.

What are angle brackets in C?

angular brackets are used for global use of the header files which are predefined and we include in our program. When you use angle brackets, the compiler searches for the file in the include path list. Angular brackets are used for standard inclusions.


1 Answers

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

NSObject<NSCoding, UITableViewDelegate> *myVariable;

In this case the class must be NSObject or a subclass (only NSProxy and its subclasses would fail), and it must also conform to both NSCoding and UITableViewDelegate protocols.

In Java or C# this would only be possible by actually declaring said class.

like image 99
PeyloW Avatar answered Oct 01 '22 11:10

PeyloW