EasyApp

Notifications

如何集中管理 NotificationCenter 的通知名称

在使用 NotificationCenter 时,您需要配置通知的名称。

NotificationCenter.default.post(
	name: "your notification name",
	object: nil,
	userInfo: ["your notification userInfo"]
)

我们不希望 NotificationCentername 散落在项目的各个地方,我们希望将它集中管理。这样为了更好组织我们的代码结构。我们约定将项目中所有 NotificationCentername 都放在 EasyAppSwiftUI/Constants/Constants.swift 文件中。

enum Constants {
	enum Notifications {
		static let yourNotificationName = Notification.Name("your notification name")
	}
}

Last updated on