Search code examples
pyobjc

Where is objc.signature documented?


I am trying to implement a delegate for an NSWebView, however when I run it, I get this error:

TypeError: Error when calling the metaclass bases
    class Delegate does not correctly implement protocol WebScripting: the signature for method isSelectorExcludedFromWebScript: is c@:: instead of Z@::

Where can I find documentation for 'c@::', as opposed to 'Z@::', and what might be wrong with my code?

The method in question is as follows:

def isSelectorExcludedFromWebScript_(self, sel):
    return True

Specifically, the NSWebView is documented at: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/index.html (But I suspect that Apple will move this URL in future)

More precisely, the delegate's informal protocol I am attempting to use is documented here: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebFrameLoadDelegate_Protocol/index.html#//apple_ref/doc/uid/TP40003828 and https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebScripting_Protocol/index.html#//apple_ref/doc/uid/TP40001562

The only documentation for objc.signature I have found is at: http://pythonhosted.org/pyobjc/api/module-objc.html


Solution

  • The standard objective-c type encodings are documented in Apple's ObjC runtime reference. This defines c as char, @ as object, and : as selector, but doesn't mention Z.

    PyObjc adds a few that aren't on that list, described in http://pythonhosted.org/pyobjc/api/module-objc.html#objective-c-type-strings by reference to a bunch of constants in the objc module. objc._C_NSBOOL has the value Z (also mentioned in the pyobjc BridgeSupport docs)

    So it looks like the problem has to do with the conversion of Python's True to the correct objective c type, but I'm not sure how to correct the problem.