ios - 我如何访问此打印输出的一部分

标签 ios

不确定如何表达,但基本上我正在这样做:

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] 或其他东西一样访问它?

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

最佳答案

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

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);

关于ios - 我如何访问此打印输出的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19729119/

相关文章:

ios - 混合 Swift 和 Objective C : "ProjectName-Swift.h" file not found

ios - 为什么 UIView 在 offsetBy 上向右移动

ios - 动画边界更改时具有 CALayer 有线效果的自定义 View

android - NodeJS + SocketIO 推送到移动应用

ios - 快速将十六进制转换为十进制

ios - NSURLConnection 在释放 NSMutableData 时崩溃

ios - 选择 DatePicker Swift 4 的默认值

ios - 登录和完成处理程序

ios - SQLite DateTime 列接受任何值......正常吗?

ios - 如何在 Swift 中比较两点