Skip to content

REN-LEI/RENNotificationCenter

Repository files navigation

RENNotificationCenter

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"];

安装

CocoaPods

  • Podfile 里添加以下依赖:
pod 'RENNotificationCenter', '~> 0.0.4'
  • 运行 pod install

###源文件

直接导入源文件。

  • 下载最新代码
  • 导入 RENNotificationCenter.hRENNotificationCenter.m

##感谢 本人通过阅读Facebook开源的KVOController源码后,基于其思想实现了RENNotificationCenter

License

基于 MIT 协议

About

一个小巧轻量的NSNotificationCenter的封装

Resources

License

Stars

Watchers

Forks

Packages

No packages published