3

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

Arafangion
  • 11,517
  • 1
  • 40
  • 72
  • Incidentially, I did read http://pseudofish.com/showing-a-nssavepanel-as-a-sheet.html however, it seems that *every single link to apple's dev documentation is broken*. Shame on Apple. – Arafangion Nov 06 '15 at 06:27
  • I was able to go [here](https://developer.apple.com/library/mac/navigation/) and search for NSSavePanel. However, NSWebView returned no results, nor did objc.signature, nor did isSelectorExcludedFromWebScript. Either a poor search algorithm, incomplete doc, or the API has changed significantly. – Bacon Bits Nov 09 '15 at 01:20
  • @BaconBits: I've provided explicit references in the question now - thanks for that. :) – Arafangion Nov 09 '15 at 01:27

1 Answers1

2

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.

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50
  • That's an insightful response. I have attempted to specify the selector signature, but I don't seem to be able to do so correctly. I'm not sure if that #type-encodings section is describing the signature types as it doesn't mention 'c'. I wonder, however, if it's related to this particular method being a _class_ method rather than an instance method. – Arafangion Nov 09 '15 at 02:28
  • There's another reference at http://pythonhosted.org/pyobjc/api/module-objc.html#objective-c-type-strings which describes these strings in terms of constants defined in the `objc` module. `objc._C_BOOL` is `c` and `objc._C_NSBOOL` is `Z`. – Ben Darnell Nov 09 '15 at 15:11
  • That actually starts to make some sense now, I didn't think to look at the values of those constants. I'm hoping to work out how to correct the problem I have, but as it stands, it looks like you may yet win the bounty. :) (Especially if you put that comment involving objc._C_NSBOOL into the answer properly) – Arafangion Nov 10 '15 at 01:34
  • 1
    I think this is probably the best answer that can be expected under the circumstances - pyobjc, objc, and apple's documentation being how they are. – Arafangion Nov 10 '15 at 23:14