Need help with Swift and MIDI Networking on macOS

Hello,

I hope you can help me solve the following problem. I'm completey new to Obj-C, or Swift, but have some experience in C and scripting languages. I'm under time pressure, so I hope you can excuse that I don't have the room to learn Swift from the ground up.

I have a mac in a recording-studio environment that needs to establish a network MIDI connection (MIDI = protocol to send musical notes) to another device on the network and reliably reestablish this connection after reboot. By GUI, you can do this in the Audio-MIDI-Setup window:

Applications --> Utilitys --> Audio-MIDI-Setup --> Window --> Show MIDI-Studio --> "Globe Icon".

You set up a "Session" and if the other device doesn't support Bonjour and appear in the "Directory" list by itself, you manually add it to the list on the left (by Name, IP, Port). Then you can select it and click "Connect". There is a tick-box to "automatically reconnect" but from my experience, it simply doesn't work. That's the reason, why I need to do all of this in a code snippet.

I looked at the Apple Developer Docs and under MIDI Networking, there are three object-classes that I need:

MIDINetworkHost
MIDINetworkConnection
MIDINetworkSession

From my understanding, a MIDINetworkHost is a device that would appear in the "contacts" list.

As I'm struggeling alot with the Swift syntax, I would be very thankful if you could help me and point me in the right direction on how to create and handle these objects and connect them to each other.