什么是尖括号“< ...>”在Obj-C类接口中? [英] What are the angle brackets "<…>" in an Obj-C class interface for?
问题描述
任何人都可以告诉我什么尖括号< ...>在Obj-C类接口中做?像这样... http://snipt.net/robhawkes/cocoa-class-interface
@interface MapMeViewController:UIViewController< CLLocationManagerDelegate,MKReverseGeocoderDelegate,MKMapViewDelegate,UIAlertViewDelegate> {…
我以前有网络语言(PHP,JavaScript)和ActionScript的编程经验。从我的观点,他们看起来像一些类型的声明,像我们确保 MapMeViewController
是一个 CLLocationManagerDelegate,MKReverseGeocoderDelegate,MKMapViewDelegate或UIAlertViewDelegate
类,它们是
UIViewController
类。
有关 @interface
语法的文档似乎没有提及。
类接口定义中的尖括号表示您的类符合的协议。
一个协议几乎就像一个接口在Java或C#中,另外一个Objective-C协议中的方法可以是可选的。
另外在Objective-可以声明变量,参数或实例变量以符合多个协议。示例
NSObject< NSCoding,UITableViewDelegate> * myVariable;
在这种情况下,类必须是 NSObject
或者一个子类(只有 NSProxy
,它的子类会失败),它也必须符合 NSCoding
和<$ c / c>
在Java或C#中,只有通过实际声明该类才能实现。
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> { …
I've previous programming experience with web languages (PHP, JavaScript) and ActionScript. From my view they look like some sort of type declaration, like we're making sure MapMeViewController
is a CLLocationManagerDelegate, MKReverseGeocoderDelegate, MKMapViewDelegate, or UIAlertViewDelegate
class that they are a UIViewController
class. Perhaps?
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
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.
这篇关于什么是尖括号“< ...>”在Obj-C类接口中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!