EasyApp

Notifications

How to centrally manage NotificationCenter notification names

When using NotificationCenter, you need to configure notification names.

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

We don't want the NotificationCenter name to be scattered throughout various parts of the project. We want to manage them centrally for better code organization. We agreed to put all NotificationCenter name in the project in the EasyAppSwiftUI/Constants/Constants.swift file.

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

Last updated on