• [OC Foundation框架


    1.判断某个对象是否属于一个类

    1         Student *stu = [[[Student alloc] init] autorelease];
    2         BOOL result= [stu isKindOfClass:[Person class]];
    3         NSLog(@"%i", result);
    4        
    5         //判断对象是否属于某个类,不包括子类
    6         NSLog(@"%i",[stu isMemberOfClass:[Student class]]);
    7         NSLog(@"%i",[stu isMemberOfClass:[Person class]]);
     
    2.间接调用对象的一个方法
    1         //间接调用
    2         [stu performSelector:@selector(test)];
    3         [stu performSelector:@selector(test2:) withObject:@"ABC"];
    4        
    5         //延迟调用,单位sec
    6         [stu performSelector:@selector(test2:) withObject:@"yuoo" afterDelay:2];
     
    3.类名反射,方法反射
     1 void reflect()
     2 {
     3     //类的反射
     4     NSString *str = @"Person";
     5     Class class = NSClassFromString(str);
     6    
     7     Person *p = [[class alloc] init];
     8     NSLog(@"%@", p);
     9    
    10     NSString *str2 =  NSStringFromClass([Person class]);
    11    
    12     //方法的反射
    13     NSString *method = @"test";
    14     SEL selector = NSSelectorFromString(method);
    15     NSLog(@"reflect method:");
    16     [p performSelector:selector];
    17 }
     
  • 相关阅读:
    html问题记录20180529
    html问题记录20180518
    html问题记录20180515
    Redis持久化--AOF
    Redis持久化--RDB
    Redis事件模型
    两个字符串的编辑距离-动态规划方法
    Reactor事件模型在Redis中的应用
    事件驱动模式--Reactor
    IO多路复用--总结
  • 原文地址:https://www.cnblogs.com/hellovoidworld/p/4119425.html
Copyright © 2020-2023  润新知