I have a class which acts as a generic proxy for forwarding delegates. By implementing respondsToSelector and forwardInvocation I am able to use this class to forward selectors that would be sent to a delegate for various UI controls.
The problem is that when I use this class I get a compiler warning. For example, if I use it to forward messages to the UITableViewDelegate:
DelegateForwarder* _forward = [[DelegateForwarder alloc] init];
_tableView.delegate = _forward;
I get the compiler warning:
Assigning to id<UITableViewDelegate> from incompatible type 'DelegateForwarder'
I know that the warning is generated because DelegateForwarder does not adopt the UITableViewDelegate delegate, but I do not want it to – because the forwarding mechanism it provides is entirely generic.
Despite the warning my code runs as intended.
Is there anything I can do to indicate in some way to the compiler and users of this class that it uses message forwarding, so the fact that it does not adopt a specific protocol is not an issue?
Expanding on the comments….
Since
idis called a “generic object type”, it’s use is a signal to the type-checking mechanism that the nature of the referenced object is to be considered completely dynamic. This means that code such as……implies that the
DelegateForwardervariable should be checked for conformance, whereas……is a “trust me” type of declaration.