[英]What's the iOS equivalent of MesagingCenter?
如何在 iOS 中的不同組件之間發送消息?
即如何使用 iOS...來做到這一點?
MessagingCenter.Send<object>(this, "LoggedIn");
那是通知中心
要使用它,定義你的通知,注冊一個觀察者,最后發布通知,例如
let loggedIn = Notification.Name("LoggedIn")
let nc = NotificationCenter.default
nc.addObserver(forName: .loggedIn, object: nil, queue: nil) { _ in
// handle loggedIn notification
}
// ... elsewhere: post
nc.post(name: .loggedIn, object: nil)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.