小编Lin*_*ngs的帖子

NSNotificationCenter如何检测ARC中的解除分配的观察者?

我发现NSNotificationCenter在ARC中使用时,即使你忘记删除了observerfrom defaultCenterobserverhas deallocated,然后你发布了观察者观察到的通知,也没有崩溃了!

在Xcode 4之前,没有ARC,我们必须observerdealloc功能中删除默认通知中心,如下所示:

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
Run Code Online (Sandbox Code Playgroud)

否则当发布绑定通知时,它会发生崩溃!

所以,问题是如何在NSNotificationCenter检测解除了分配observerARC

objective-c nsnotificationcenter automatic-ref-counting

0
推荐指数
1
解决办法
2131
查看次数