Swift iOS Plugin: Swift to Unity Comunication

Hi,

I am working on an iOS plugin.
Communicating from Unity to iOS Swift was not hard, but the reverse is complicated.
However, when I calculate something in Swift, I want to be able to pass it to Unity.
I know all about UnitySendMessage, but there are two issues with it.

  1. Most of the plugins that use it are really small, including 1-2 Swift scripts. And they all seem to be already inside Unity. My plugin contains 20-30 plugins packed in a Swift Package with multiple dependencies. It is a standalone project, and if I want to include UnityFramework or UnitySendMessage(), I am flooded with errors, which I don’t know how to fix.
  2. My projects is a standalone Local Swift Package, which is aimed to be used in iOS as well, not just Unity. And I want to keep it platform-independent.

Keeping this mind, the only solution seems to be using delegates: Unity - Manual: Native plug-ins for iOS

This article described how to achieve the Unity to Swift communication better than all other articles I have seen so far: Setting Up iOS Framework for Unity | by Max Kalik | Better Programming

However, it does not address the Swift to Unity communication part.

How I can communicate from Swift to Unity?
Something like this would be nice:

void OnEnable()
{
    iOSPlugin.DelegateFunction += ParseSwiftMessage;
}

Whenever the DelegeteFunction is raised in Swift, I want to receive that in Unity to the ParseSwiftMessage function. Just like subscribing to the usual Unity C# delegates/events.

Thanks.

If someone is looking for a solution, take a look at these two repos.

Nonetheless, this has been resolved. Thanks.