Search code examples
objective-cuiviewruntimesubviews

Why iOS cannot get subviews property for class UIView using class_getProperty function?


I want to get the information about subviews property of class UIView:

objc_property_t property = class_getProperty([UIView class], "subviews");

But, it returns nil? I think it is so strange. Could someone explain this behavior to me?


Solution

  • Weird. If you use -valueForKey:, it can clearly be shown to exist. This used to be a bug with the old LLVM clang compiler in Xcode 3.2.3, where properties in categories (yes, it is declared in a category on UIView) wouldn't get recognized by the runtime, and there was even a bug report filed here about it. I know recent versions of Xcode have been having trouble with categories of late...