Hello, I'm developing a Mac application that uses a network extension. I'm trying to implement XPC to pass data between my main app and system extension and I'm using the SimpleFirewall demo app as a guide to do this. One thing I can't understand is how the ViewController in the SimpleFirewall main app has access to the class IPCConnection in the SimpleFirewallExtension without it being public and without SimpleFirewallExtension being imported in ViewController.
The view controller accesses the IPC object via the IPCConnection.shared
singleton. This has no access control modifiers, so it defaults to internal
. The IPCConnection.swift
is built in to both the app and the sysex, and thus both of those can see these internal declarations.
It’s not uncommon for an NE product to use a framework to share code between the container app and the {app,sys}ex. However, that’s not required. In this simple example, the project just compiles the IPCConnection.swift
twice, once for each target.
IMPORTANT If you do decide to add a framework to your product, make sure to embed it in the sysex, not in the app. That’s necessary because, when you install the sysex, the system copies it out of your app to a private location, and you have to make sure that the framework gets copied along with it.
Doing this requires an rpath tweak. To learn more about that concept, see Dynamic Library Standard Setup for Apps.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"