In Objective C, can you check if an object has a particular property or message?
Solution 1:
For ordinary selectors, you can use respondsToSelector:
. I'm not certain if this will work for new-style property access (as it appears you are using in this example). To test if a class responds to a given selector, use instancesRespondToSelector:
.
Solution 2:
Also, As Jason poninted out here, you can also use NSSelectorFromString
to dynamically check at runtime. E.g.
if ([self respondsToSelector:NSSelectorFromString(elementName)])
{
[self setValue:elementInnerText forKey:elementName];
}
Solution 3:
Oops, found it:
if ([vc respondsToSelector:@selector(mapView)]) {
[[vc mapView] viewWillAppear:YES];
}