I have a macOS app with a plugin system, where plugins are loaded at runtime and add functionality. Sadly, it is impossible to make this work purely in Swift because runtime loading requires the Objective-C runtime. (I can cast the principle class of the loaded bundle only if it is defined in Objective-C. See http://blog.pendowski.com/plugin-architecture-in-swift-ish/ for en example not un-similar to mine)
My question is now if there is any way to make the following work. Maybe I am just missing something.
I have Swift structs that represent my entities (SPM framework that represents the “model”). Those are also used on the server, so no classes possible with
@objc. Since those are used to serialize to and from JSON for communication with the server, I’d also want to use them for exchanging data with any plugin. (Previously I passed around CoreData objects but that just blows because of model versioning and security etc.)
The problem now is, how do I pass them to the plugin or receive them back? The plugin will get the “ModelFramework” which is pure Swift linked, as well as the “PluginAPIFramework” which is pure Objective-C.
Am I missing something here? I mean I can’t jut box the structs into a generic box, because once they go through the plugin interface, they are just of an Objective-C protocol type and not recoverable. Right?