b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

面向对象开发过程 iOS开发:Runtime解析(5)

电脑杂谈  发布时间:2018-02-20 21:52:40  来源:网络整理

@interface Person : NSObject

/** 姓名 */

@property (strong, nonatomic) NSString *name;

/** age */

@property (assign, nonatomic) int age;

/** weight */

@property (assign, nonatomic) double weight;

@end

以上是一个 Person 类,有3个属性。让我们用上述方法获取类的运行时属性。

unsigned int outCount = 0;

objc_property_t *properties = class_copyPropertyList([Person class], &outCount);

NSLog(@"%d", outCount);

for (NSInteger i = 0; i < outCount; i) {

NSString *name = @(property_getName(properties[i]));

NSString *attributes = @(property_getAttributes(properties[i]));

NSLog(@"%@--------%@", name, attributes);

}

打印结果如下:

test[1525] 3

test[1525] name--------T@"NSString",&,N,V_name

test[1525] age--------Ti,N,V_age

test[1525] weight--------Td,N,V_weight

property_getName 用来查找属性的名称,返回 c 字符串。property_getAttributes 函数挖掘属性的真实名称和 @encode 类型,返回C字符串。

objc_property_t class_getProperty(Class cls, const char *name)

objc_property_t protocol_getProperty(Protocol *proto, const char *name, BOOL isRequiredProperty, BOOL isInstanceProperty)

class_getProperty 和 protocol_getProperty 通过给出属性名在类和协议中获得属性的引用。


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-86234-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...