I recently needed to use NSMachPort for some interprocess communication on macOS. However, these days it is hard to find examples of how to use it in Apple's official documentation, as they are steering everyone toward XPC services and NSXPCConnection for sandboxed IPC.
So, I wrote my own simple example code for NSMachPort. If you need it, you can find it at https://github.com/kristopherjohnson/KJMachPortServer.