-
conformsToProtocol:@protocol()的理解和用法
- @protocol MyProtocol
-
- - (void) doSomething;
-
- @end
-
- @interface MyClass : NSObject<MyProtocol>
- {
- }
-
- @end
-
- @implementation MyClass
-
- - (void) doSomething {
- }
-
- @end
-
- @interface MyOtherClass : MyClass
- {
-
- }
-
- @end
-
- @implementation MyOtherClass
-
- - (void) doSomething {
- }
-
- @end
-
-
- int main (int argc, const char * argv[])
- {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-
- MyClass *obj_one = [MyClass new];
- BOOL one_conforms = [obj_one conformsToProtocol:@protocol(MyProtocol)];
-
- MyOtherClass *obj_two = [MyOtherClass new];
-
-
-
- BOOL two_conforms = [obj_two conformsToProtocol:@protocol(MyProtocol)];
- NSLog(@"obj_one conformsToProtocol: %d", one_conforms);
- NSLog(@"obj_two conformsToProtocol: %d", two_conforms);
- [pool drain]; return 0;
- }
-
-
- obj_one conformsToProtocol: 1
- obj_two conformsToProtocol: 1
-
-
- MyOtherClass *obj_two = [MyOtherClass new];
-
- BOOL conforms_two = class_conformsToProtocol([obj_two class], @protocol(MyProtocol));
- NSLog(@"obj_two conformsToProtocol: %d", conforms_two);
-
-
- obj_two conformsToProtocol: 0
-
相关阅读:
让Dreamweaver支持cshtml (MVC Razor环境)
href="#"与href="javascript:void(0)"的区别
ASP.NET MVC 4 中Razor 视图中JS无法调试 (重要)
03011_HttpServletRequest
1004. 成绩排名 (20)
1003. 我要通过!(20)
C语言文件读写命令fprintf和fscanf
1002. 写出这个数 (20)
1001. 害死人不偿命的(3n+1)猜想 (15)
汇编in和out实例解析
-
原文地址:https://www.cnblogs.com/linyawen/p/2554834.html
Copyright © 2020-2023
润新知