Using the Objective-C protocol from my XPC service in my Swift application

I have an application written in Swift, exclusively in Swift, which never had an Obj-C class, no Obj-C files or bridges.

To add some features without affecting the rights to my applications, I am trying to add an XPC service - I created it in Xcode, and the template for XPC services in Xcode is just Obj-C.

This is normal, I wrote my service in Obj-C, but now when I want to call the service through NSXPCConnection, I need to configure the interface, and for this I need to go, in my Swift application code, to the Obj-C protocol that I wrote for my purpose XPC.

How can I do it? I can’t just add “Protocol.h” to my target program, it doesn’t have a rule for the C header. All the other comments that I found regarding this seem to apply to the protocol binding within the framework or general purpose ...

+4
source share
2 answers

Ok, so I understood the solution.

1) Removed standard classes and protocol files Obj-C.

2) Wrote my protocol and extended object classes in swift. Make sure they can be exported to Obj-C.

3) Added protocol.swift file for my application. Added #import "Service-Swift.h"to my service main.m.

, XPC Swift, , XPC.

+3

Source: https://habr.com/ru/post/1606467/


All Articles