I have two classes A and B. Class A gives class B a target/action pair which class B callbacks later. The target is self (= class A), action is a callback method. The callback is later done with:
[target performSelector:action withObject:anObject];
The method action is only called by this callback. It works fine if I don’t declare the method in .h file of class A. But my question is, is that a bad design to not declare it in the .h file? Since the method is only called in callbacks, I think it is not nescessary to declare it, isn’t it? I mean, the callback “performSelector” even can’t check if the method exists at runtime. So what is your suggestion?
No, it isn’t, really. I often see this pattern and in fact, I don’t declare these callback-/delegate-only methods.
But yes it can, thanks to reflection; just write something like this:
But if you’re really worried about this, you’d be better off with using blocks for simple callbacks instead of delegates.