在命令式Swift中,通常使用计算属性在不复制状态的情况下提供对数据的便捷访问。 假设我将此类用于命令式MVC: class ImperativeUserManager { private(set) var currentUser: User? { didSet { if oldValue != currentUser { NotificationCenter.default.post(name: NSNotification.Name("userStateDidChange"), object: nil) // Observers that receive this notification might then check either currentUser or userIsLoggedIn for the latest state } } } var userIsLoggedIn: Bool { currentUser != nil } // …