博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取类的属性列表、方法列表、实例变量列表
阅读量:6973 次
发布时间:2019-06-27

本文共 2463 字,大约阅读时间需要 8 分钟。

hot3.png

unsigned int ivarCount = 0;    Ivar *ivars = class_copyIvarList([User class], &ivarCount);        for (unsigned int i = 0; i < ivarCount; i++) {        Ivar ivar = ivars[i];        const char *name = ivar_getName(ivar);        NSLog(@"ivar name = %@", [NSString stringWithUTF8String:name]);                ptrdiff_t offset = ivar_getOffset(ivar);        NSLog(@"ivar offset = %zd", offset);                const char *encoding = ivar_getTypeEncoding(ivar);        NSLog(@"ivar type = %@", [NSString stringWithUTF8String:encoding]);    }    free(ivars);        unsigned int methodCount = 0;    Method *methods = class_copyMethodList([User class], &methodCount);        for (unsigned int i = 0; i < methodCount; i++) {        Method method = methods[i];                SEL sel = method_getName(method);        NSLog(@"method name = %@", NSStringFromSelector(sel));                char *returnType = method_copyReturnType(method);        NSLog(@"method returnType = %@", [NSString stringWithUTF8String:returnType]);        free(returnType);                const char *typeEncoding = method_getTypeEncoding(method);        NSLog(@"method typeEncoding = %@", [NSString stringWithUTF8String:typeEncoding]);                unsigned int argumentCount = method_getNumberOfArguments(method);        for (unsigned int i = 0; i < argumentCount; i++) {            char *argumentType = method_copyArgumentType(method, i);            NSLog(@"method argumentType = %@", [NSString stringWithUTF8String:argumentType]);            free(argumentType);        }    }    free(methods);        unsigned int propertyCount = 0;    objc_property_t *propertys = class_copyPropertyList([User class], &propertyCount);        for (unsigned int i = 0; i < propertyCount; i++) {        objc_property_t property = propertys[i];                const char *name = property_getName(property);        NSLog(@"property name = %@", [NSString stringWithUTF8String:name]);                unsigned int attCount = 0;        objc_property_attribute_t *attributes = property_copyAttributeList(property, &attCount);        for (unsigned int i = 0; i < attCount; i++) {            objc_property_attribute_t att = attributes[i];            NSLog(@"attribute name = %@", [NSString stringWithUTF8String:att.name]);            NSLog(@"attribute value = %@", [NSString stringWithUTF8String:att.value]);        }        free(attributes);    }    free(propertys);

 

转载于:https://my.oschina.net/mexiaobai1315/blog/1806766

你可能感兴趣的文章
系统升级与优化
查看>>
网络编程之urllib
查看>>
Simple Python Dictionary :)
查看>>
c语言程序设计第六次作业--循环结构(二)
查看>>
【转】WebView的JavaScript与本地代码三种交互方式
查看>>
xml转换为对象 微信接口
查看>>
软件产品案例分析
查看>>
HTML表单
查看>>
四元数
查看>>
bzoj2125: 最短路
查看>>
P4781 【模板】拉格朗日插值
查看>>
jzoj5984. 【北大2019冬令营模拟2019.1.1】仙人掌 (分块)
查看>>
python jenkins api
查看>>
电梯调度算法的实现
查看>>
IIPC--share memory
查看>>
前端之html5和css3
查看>>
View绘制机制
查看>>
跟KingDZ学HTML5之四 继续探究Canvas之路径
查看>>
054_VisualForce Ajax 01
查看>>
Android性能优化问题总结
查看>>