AutoRemoveObserverDemo:自动删除NSNotificationCenter观察器的演示

时间:2024-06-04 09:25:13
【文件属性】:

文件名称:AutoRemoveObserverDemo:自动删除NSNotificationCenter观察器的演示

文件大小:21KB

文件格式:ZIP

更新时间:2024-06-04 09:25:13

Objective-C

AutoRemoveObserverDemo 自动释放NSNotification的Observer的实验 实验了几种做法,其中二和三可以实现, 但仅粗略验证, 可能有未知的问题. ####一、@妙玄 提供思路:外层包装一个Wrapper对象来感知Observer的释放,通过Wrapper对象来移除通知. NSNotificationCenter加一个category, 添加一个associatedObject为一个数组. 替换NSNotificationCenter的 addObserver... 方法, 新方法中用一个 Wrapper对象来封装传进来的Observer. 想通过真正的observer被释放时触发wrapper的 realObserver setter方法, 从而移除通知. //Wrapper.h @interface Wrapper : NSObject @proper


【文件预览】:
AutoRemoveObserverDemo-master
----.DS_Store(6KB)
----noteTest.xcodeproj()
--------project.xcworkspace()
--------project.pbxproj(19KB)
----noteTestTests()
--------Info.plist(753B)
--------noteTestTests.m(857B)
----README.md(3KB)
----noteTest()
--------LBSingleton.h(996B)
--------ViewController.m(1KB)
--------NSObject+Utils.m(3KB)
--------Info.plist(739B)
--------ClassFoo.m(255B)
--------main.m(329B)
--------NSObject+Utils.h(846B)
--------APFakeObserver.m(2KB)
--------NSNotificationCenter+Add.m(1KB)
--------APFakeObserver.h(447B)
--------Base.lproj()
--------Images.xcassets()
--------NSNotificationCenter+Add.h(341B)
--------LBWeakList.h(456B)
--------ClassFoo.h(240B)
--------ViewController.h(210B)
--------AppDelegate.h(272B)
--------LBWeakList.m(1KB)
--------AppDelegate.m(2KB)

网友评论