Objective-C is a little less strict than Java in terms of input, so you will need to check it at runtime.
Note that the two code below does the exact same thing, except that the former checked the object for full compliance with the protocol, while the latter simply checks the method you want to call.
for (id object in listeners) { if ([object conformsToProtocol:@protocol(myProtocol)]) { [object firstMethod];
Or,
for (id object in listeners) { if ([object respondsToSelector:@selector(firstMethod)]) { [object firstMethod];
source share