I have an existing (Catalyst) app "A". I want it to offer an XPC Service which can be connected by another (macOS) App "B".
I have added an xpc target to app "A" using Xcode and set it up according to https://matthewminer.com/2018/08/25/creating-an-xpc-service-in-swift.html . The xpc target compiles and I have added the resulting .xpc file to App "A"'s "Frameworks, Libraries, etc." in Xcode.
When I execute App "A" no code of the xpc target is executed. I would expect that main.swift of the xpc target is executed in order to start the listener when I start App "A". But neither breakpoints are hit, nor log messages do appear on console.
main.swift:
import Foundation
NSLog("Service has started")
let delegate = MyServiceDelegate()
let listener = NSXPCListener.service()
listener.delegate = delegate
listener.resume()
When I put the code from main.swift directly into App "A"s init() I get a crash at listener.resume().
Can anybody explain how is xpc stuff is launched ? I don't want a solution using launchd, the XPC listener should run, whenever app "A" runs.