美文网首页
ios中runtime 笔记

ios中runtime 笔记

作者: 蚯小麦 | 来源:发表于2020-12-09 10:40 被阅读0次

    常见方法

    1.获取属性列表

    unsigned int count;
    objc_property_t *propertyList = class_copyPropertyList([self class], &count);
        for (unsigned int i=0; i<count; i++) {
            const char *propertyName = property_getName(propertyList[i]);
            NSLog(@"property---->%@", [NSString stringWithUTF8String:propertyName]);[/i]
      }
    

    2.获取方法列表

    Method *methodList = class_copyMethodList([self class], &count);
    for (unsigned int i; i<count; i++) {
        Method method = methodList[i];
        NSLog(@"method---->%@", NSStringFromSelector(method_getName(method)));
    }
    

    3,获取成员变量列表

    Ivar *ivarList = class_copyIvarList([self class], &count);
      for (unsigned int i; i<count; i++) {
          Ivar myIvar = ivarList[i];
          const char *ivarName = ivar_getName(myIvar);
          NSLog(@"Ivar---->%@", [NSString stringWithUTF8String:ivarName]);
      }
    

    4,获取协议列表

    __unsafe_unretained Protocol **protocolList = class_copyProtocolList([self class], &count);
        for (unsigned int i; i<count; i++) {
            Protocol *myProtocal = protocolList[i];
            const char *protocolName = protocol_getName(myProtocal);
            NSLog(@"protocol---->%@", [NSString stringWithUTF8String:protocolName]);
        }
    

    5,获得类方法

    相关文章

      网友评论

          本文标题:ios中runtime 笔记

          本文链接:https://www.haomeiwen.com/subject/iktnfftx.html