在 Mac/iOS 个应用程序 (Swift) 中实施调解器模式

Implementation of the Mediator pattern in Mac/iOS apps (Swift)

是否有类似于 MVVM Light Messenger 的 Mac/iOS 库,允许在对象之间交换消息(最好用 swift 编写)?

我在我的许多 WPF 应用程序中都使用了这种调解器模式 - 它对我很有帮助,因为它减少了我的 ViewModel(和其他应用程序组件)之间的耦合。但最近我开始学习原生 Mac 应用程序的开发,但我找不到任何描述模式的实现。

我想 NSNotificationCenter 就是你需要的。

A notification encapsulates information about an event, such as a window gaining focus or a network connection closing. Objects that need to know about an event (for example, a file that needs to know when its window is about to be closed) register with the notification center that it wants to be notified when that event happens. When the event does happen, a notification is posted to the notification center, which immediately broadcasts the notification to all registered objects.

您可以在 Apple Developer Portal. Though it’s using Objective-C for examples, you can find Swift NSNotificationCenter class reference here.

找到此概念的完整描述