I am building a tool that enables the user to write, auto-compile and interact with SwiftUI code (think something like a mini Xcode Canvas). Which so far works really well.
The app is not sandboxed since it uses tools like swiftc and sourcekit-lsp.
The obvious problem here is that since the 'Preview' part of the app is driven by arbitrary code a crash/hang there would lead to a termination of the whole app.
I understand that there are some private apis like NSRemoteView or CALayerHost but I would like to avoid them if I can.
From what I see reading other similar solutions IOSurface sharing + event forwarding might be the best solution.
So my question is: Is there a proper or recommended way to achieve this? Meaning having a fully interactive SwiftUI view presented in my host app but running on a separate process?
Any pointers to the right direction or examples or whatever could help me with this would be greatly appreciated.
Implementing remote view support is hard. I’m actually good friends with the person who maintains the internal macOS support for this and, yeah, he has some stories to tell (-: So, I wouldn’t recommend that you go down this path:
From what I see reading other similar solutions IOSurface sharing + event forwarding might be the best solution.
You might be able to make it work in some cases but it’s gonna be a lot of work and it’ll likely be quite brittle.
The most promising alternative is to implement this using ExtensionKit. It has high-level support for hosting the extension’s view within your app’s view hierarchy.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"