In Objective C, can you check if an object has a particular property or message?

前端 未结 4 1397
既然无缘
既然无缘 2020-12-24 10:47

I wat to do something like this:

if (viewController.mapView) [viewController.mapView someMethod];

However, if mapView is not a class variab

4条回答
  •  爱一瞬间的悲伤
    2020-12-24 11:26

    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:.

提交回复
热议问题