RENNotificationCenter是一款非常小巧轻量的基于NSNotificationCenter
的封装,用于简化 iOS 开发中的发布订阅模式。
##特性
- 利用iOS动态性实现自动释放通知,当持有类销毁时,自动释放注册通知
- 使用blcok的方式作为事件触发的回调,简洁明了
- 支持系统的所有通知,并转发userInfo字段
[self.notification rl_subscribe:UIApplicationDidEnterBackgroundNotification block:^(NSNotification *event) {
NSLog(@"eventName = %@",event.name);
}];
[self.notification rl_subscribe:@"CustomEventName" block:^(NSNotification *event) {
NSLog(@"eventName = %@",event.name);
}];
[self.notification rl_publish:@"CustomEventName" userInfo:@"hello"];
[self.notification rl_unsubscribe:@"CustomEventName"];
- 在
Podfile
里添加以下依赖:
pod 'RENNotificationCenter', '~> 0.0.4'
- 运行
pod install
###源文件
直接导入源文件。
- 下载最新代码
- 导入
RENNotificationCenter.h
和RENNotificationCenter.m
##感谢 本人通过阅读Facebook开源的KVOController源码后,基于其思想实现了RENNotificationCenter
基于 MIT 协议