Is there any way to test selectors/methods when all you have is a proxy object?
/* Proxy which may forward
* the method to some other object */
id proxy = [UINavigationBar appearance];
/* This condition returns FALSE
* despite the fact that the method would have otherwise been
* successfully executed at its destination */
if([proxy respondsToSelector:@selector(setBarTintColor:)]){
[proxy setBarTintColor:color];
}
Apparently you cannot.
The methods suggested by other answers will break easily, here's an example:
UINavigationBarinstances respond to selectorsetTranslucent:setTranslucent:is not tagged withUI_APPEARANCE_SELECTORin the header fileTherefore the following code
will result in a crash.
The only information about which selectors conform to
UIAppearanceseems to be theUI_APPEARANCE_SELECTORmacro, which is stripped at compile-time.A runtime check doesn't look to be feasible.
For the sake of completeness, here's an awful (but practical) way of doing it.
However, this is very fragile since there's no guarantee that you're catching only the case in which the selector doesn't conform to
UIAppearance.