我正在使用以下命令获取所有ivar的列表:
Ivar *vars = class_copyIvarList([property class], &varCount);我的问题是如何从Ivar创建id?即恢复NSString或NSDictionary等。
发布于 2012-07-30 20:17:53
只需使用object_getIvar()函数即可。如下所示:
uint varCount;
Ivar *vars = class_copyIvarList([property class], &varCount);
// Get the first one (out of an instance of this class)
// Of course you could just iterate and get each one
id var = object_getIvar(property, vars[0]);
// Free the array when you're done
free(vars);发布于 2012-07-30 20:30:11
这种方法可以简化您的转换代码:
id obj = [p valueForKey:[NSString stringWithUTF8String:ivar_getName(anIvar)]];
...https://stackoverflow.com/questions/11720544
复制相似问题