ios - postNotificationName 是否保证立即发送给监听者?

标签 ios cocoa-touch nsnotificationcenter nsnotification

如果我愿意

[[NSNotificationCenter defaultCenter] postNotificationName:@"N" object:self];
NSLog(@"here");

在执行NSLog(@"here");之前,会同步通知观察者...如果所有对象都在同一个线程上,是否保证同步执行(立即)?

找不到明确说明的内容

最佳答案

是的,虽然埋得很好:

Using the NSNotificationCenter’s postNotification: method and its variants, you can post a notification to a notification center. However, the invocation of the method is synchronous: before the posting object can resume its thread of execution, it must wait until the notification center dispatches the notification to all observers and returns.

来源:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Notifications/Articles/NotificationQueues.html

关于ios - postNotificationName 是否保证立即发送给监听者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38944228/

相关文章:

ios - session 无效。请重新登录appcelerator

ios - 从 UITableViewCell 中删除 UITableView 行?

ios - 如何确定 UIWebView 的内容大小?

ios - swift 3/4 : SearchBar not filtering results properly in TableView

iphone - iOS 模拟器只列出最新的 iOS 版本。如何设置早期版本

ios - 删除单元格之前提醒 Controller Swift Xcode

ios - CFReadStreamRead 中的 EXC_BREAKPOINT 崩溃

iphone - 如何在重置之前更新密码标签?

ios - 当我的应用程序在后台运行时,是否可以在通知上设置 PresentationsOptions?

ios - 使用 PNReachability 类检查互联网连接