ios - Mac/iOS 应用程序中中介者模式的实现 (Swift)

标签 ios swift macos mediator

是否有类似于 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 找到此概念的完整描述。 .虽然它使用 Objective-C 作为示例,但您可以找到 Swift NSNotificationCenter 类引用 here .

关于ios - Mac/iOS 应用程序中中介者模式的实现 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33743160/

相关文章:

c++ - 在 MacOS 上进行多线程 C++ 调试的好工具?

iphone - 在 .app 文件中创建一个文件夹

iOS 8 UINavigationBar 与 StatusBar 重叠

ios - 数字和名称的复数化(swift stringsdict)

c++ - 是否有某种工具或助手可以将 MFC/C++ 应用程序移植到 OS X/Cocoa?

python - 无法安装 nlopt python 模块

ios - 如何为 AppDelegate 中的所有 View Controller 独立更改左右栏按钮项文本属性?

ios - 在 iOS 中离开 View 之前要求用户确认

Swift 4 Codable解码json

ios - 如何在ios中实现刷新 token