0

不知道该怎么说,但基本上我正在这样做:

unsigned int propCount = 0;
objc_property_t *properties = class_copyPropertyList([self class], &propCount);

for(int idx = 0; idx < propCount; idx++) {
    objc_property_t prop = *(properties + idx);
    NSString *key = @(property_getName(prop));
    NSString *key2 = @(property_getAttributes(prop));

    NSLog(@"%@::%@", key,key2);
}

它打印出来

describeOther::T@"UITextField",&,N,V_describeOther

如何将“UITextField”分配给某个东西,或者它是否已经分配,​​我可以像 key2[1] 或其他东西一样访问它?

编辑:我想我可以做一个包含约束的 if 语句,但不确定这是否是“最干净”的方法。

4

1 回答 1

1

获取两个双引号的范围并提取这两个范围之间的子字符串。

NSRange openQuote = [key2 rangeOfString:@"\""];
NSRange closeQuote = [key2 rangeOfString@"\"" options:NSBackwardsSearch];

NSUInteger start = openQuote.location + openQuote.length;
NSUInteger end = closeQuote.location;
NSRange nameRange = NSRangeMake(start, end - start);
NSString *name = [keys substringWithRange:nameRange);
于 2013-11-01T14:54:13.283 回答