Objective-C: how to check if a protocol object is a special class

This java code works:

public void executeCommand(ICommand cmd) { // ICommand is an Interface if (cmd.getClass().equals(LoginCommand.class)){ } } 

But this Objective-C-Code does not work:

 - (void)executeCommand: (id<Command>)cmd { // Command is a Protocol if ([cmd isKindOfClass:[LoginCommand class]]) { // WARNING: '-conformsToProtocol:' not found in protocol } } 
+4
source share
1 answer

When you declare your protocol, tell it to inherit from the NSObject protocol, like this:

 @protocol Command <NSObject> ... @end 

link here . NSObject is a basic protocol that implements -conformsToProtocol:

+15
source

All Articles