Skip to content

Commit daa1787

Browse files
Actually add detailed information about the workaround
1 parent 0c3af43 commit daa1787

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/notes/using-nsxpcinterface.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Using NSXPCInterface from Python
2+
================================
3+
4+
The Foundation class ``NSXPCInterface`` requires an Objective-C
5+
protocol to define the API of the interface. Those protocols
6+
cannot be defined in Python using :class:`objc.formal_protocol`
7+
because the Cocoa class requires some data ("extended method sigantures")
8+
that cannot be registered using the public API for the Objectie-C
9+
runtime.
10+
11+
If you do try to use a protocol defined in Python with ``NSXPCInterface``
12+
you'll get an error similar to this:
13+
14+
::
15+
NSInvalidArgumentException - NSXPCInterface: Unable to get extended method signature from Protocol data (MyProtocol / runCommand:withReply:). Use of clang is required for NSXPCInterface.
16+
17+
18+
This means that any custom protocols that will be used
19+
with ``NSXPCInterface`` need to be defined in a C extension which
20+
is compiled using the clang compiler (the compiler used by Xcode).
21+
22+
The compiler will elide protocol information from the binary for
23+
all protocols that aren't actually used. To ensure that the protocol
24+
information is included add an (unused) function that appears to
25+
use the protocol, for example:
26+
27+
.. sourcecode:: Objective-C
28+
29+
static void use_protocol(void) __attribute__((__unused__))
30+
{
31+
printf("%p\n", @protocol(MyProtocol));
32+
}

0 commit comments

Comments
 (0)