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

前端 未结 4 1392
既然无缘
既然无缘 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:30

    Oops, found it:

    if ([vc respondsToSelector:@selector(mapView)]) {
    
      [[vc mapView] viewWillAppear:YES];
    
    }
    

提交回复
热议问题