How to get rid of the 'undeclared selector' warning

前端 未结 12 2180
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 10:53

I want to use a selector on an NSObject instance without the need for an implemented protocol. For example, there\'s a category method that should set an error prop

12条回答
  •  青春惊慌失措
    2020-12-12 11:25

    You can also cast the object in question to an id first to avoid the warning:

    if ([object respondsToSelector:@selector(myMethod)]) {
        [(id)object myMethod];
    }
    

提交回复
热议问题