-
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
-
相关阅读:
java线程与并发(二)
互联网金融时代的机遇和挑战
SQL Server获取下一个编码字符串的实现方案分割和进位
SQL Server获取下一个编码字符实现继续重构与增强
SQL Server获取下一个编码字符实现
SQL Server数字辅助表的实现
SQL Server中中数据行批量插入脚本的存储实现
SQL Server中的RAND函数的介绍和区间随机数值函数的实现
SQL Server中字符串转化为GUID的标量函数实现
SQL Server 中获取字符串拼音的标量函数实现
-
原文地址:https://www.cnblogs.com/linyawen/p/2554834.html
Copyright © 2020-2023
润新知