标签:style blog io ar color 使用 sp strong 文件
A.概念
1 @protocol MyProtocol 2 @required 3 - (void) test1; 4 5 @optional 6 - (void) test2; 7 8 - (void) test3; 9 10 @end
1 #import <Foundation/Foundation.h> 2 #import "MyProtocol.h" 3 4 @protocol MyProtocol2 <MyProtocol> 5 6 7 @end
1 @interface Person : NSObject <MyProtocol]] > 2 3 @property(nonatomic, strong) id<MyProtocol2> obj; 4 5 @end
1 int main(int argc, const char * argv[]) { 2 Person *p = [[Person alloc] init]; 3 Dog *d = [[Dog alloc] init]; 4 5 p.obj = d; // 警告,Dog没有遵守MyProtocol2协议 6 7 return 0; 8 }
1 #import <Foundation/Foundation.h> 2 3 @protocol MyProtocol; 4 @protocol MyProtocol2; 5 6 @interface Person : NSObject <MyProtocol]] > 7 8 @property(nonatomic, strong) id<MyProtocol2> obj; 9 10 @end
1 #import "Person.h" 2 #import "MyProtocol.h" 3 #import "MyProtocol2.h" 4 5 @implementation Person 6 - (void)test1 7 { 8 9 } 10 11 - (void)test3 12 { 13 14 } 15 16 @end
[Objective-c 基础 - 3.4] protocol
标签:style blog io ar color 使用 sp strong 文件
原文地址:http://www.cnblogs.com/hellovoidworld/p/4119381.html