开发者

Dynamically List IBOutlets of a Class

开发者 https://www.devze.com 2023-03-18 11:14 出处:网络
I\'ve been working with this objc_property_t *properties = class_copyPropertyList([NSString class], &outCount);

I've been working with this

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

which has two limitations that I don't know how to resolve:

  1. It doesn't list inherited properties.
  2. I can't differentiate IBOutlets fr开发者_开发问答om other properties.

How can I dynamically list all the IBOutlet properties in a class (or instance)?


IBOutlet is #defined as a blank string; it doesn't have any effect at either compile or run time. Its sole purpose is to allow Interface Builder to look at header files and see which ivars should be used as connections. The only way for you to determine which ivars were declared as IBOutlets would be to likewise do some text processing of the header file of whatever class you're working with.

For the properties, I'm not sure there's any other way than going up the list of superclasses and getting all their properties too. You can call class_getSuperclass in a loop to get the whole ancestry of your class;* the function returns Nil when you call it with the root class (NSObject) as the argument.


*See, e.g., this SO answer of mine.


from what I've read this is not possible. The reason is that IBOutlet is a macro that resolves to nothing. So there is nothing in the compiled app to detect. It is used by interface builder which looks at the raw source code where it can see it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号