title: How to connect a Catalyst app to macOS App using XPC?
body: <p>I have an existing (Catalyst) app &quot;A&quot;. I want it to offer an XPC Service which can be connected by another (macOS) App &quot;B&quot;.</p>
  <p>I have added an xpc target to app &quot;A&quot; using Xcode and set it up according to <a href="https://matthewminer.com/2018/08/25/creating-an-xpc-service-in-swift.html" rel="nofollow noreferrer">https://matthewminer.com/2018/08/25/creating-an-xpc-service-in-swift.html</a> . The xpc target compiles and I have added the resulting .xpc file to App &quot;A&quot;'s &quot;Frameworks, Libraries, etc.&quot; in Xcode.</p>
  <p>When I execute App &quot;A&quot; 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 &quot;A&quot;. But neither breakpoints are hit, nor log messages do appear on console.</p>
  <p>main.swift:</p>
  <pre><code>import Foundation
  
  NSLog(&quot;Service has started&quot;)
  
  let delegate = MyServiceDelegate()
  let listener = NSXPCListener.service()
  listener.delegate = delegate
  listener.resume()
  </code></pre>
  <p>When I put the code from main.swift directly into App &quot;A&quot;s init() I get a crash at listener.resume().</p>
  <p>Can anybody explain how is xpc stuff is launched ? I don't want a solution using launchd, the XPC listener should run, whenever app &quot;A&quot; runs.</p>