I was wondering if there is any way to formally indicate a MacRuby class conforms to an Objective-C protocol. I encountered some code that uses conformsToProtocol: instead of respondsToSelector: as a check before invoking delegate methods, and the only way I could get a delegate written in MacRuby to work was to create an Objective-C class with the same name and specify the required protocols in the interface declaration there.
Thanks,
Martijn
_______________________________________________
MacRuby-devel mailing list
MacRub...@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
*** NSInvocation: warning: object 0x7fff71192488 of class 'Protocol' does not implement methodSignatureForSelector: -- trouble ahead
*** NSInvocation: warning: object 0x7fff71192488 of class 'Protocol' does not implement doesNotRecognizeSelector: -- abort
Even just comparing it to another protocol object using protocol == Protocol.protocolWithName('...') leads to the same result.
Any ideas as to how this could be made to work?
def conformsToProtocol(protocol)
supported = %w( AProtocol SomeOtherProtocol YetAnotherProtocol
).map {|name| Protocol.protocolWithName name} # List the protocols you
want to conform to between the parns
supported.any? {|candidate| protocol.isEqual candidate } or super
end
The reason this works is because Protocol *is* a real class, but it's
derived from a base class different from NSObject. Obviously we'll
want a better solution for MacRuby, but this will work in the
meantime.
— Chuck