Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

iOS事件总线,支持AppDelegate解耦,支持基于响应链的局部总线

License

Notifications You must be signed in to change notification settings

LeoMobileDeveloper/QTEventBus

Repository files navigation

QTEventBus

Build Status Version Platform License

QTEventBus是一个优雅的iOS事件总线,用来实现"发布-订阅"的消息通信模式。

  • 支持强类型/弱类型
  • 自动取消订阅
  • 快速
  • 兼容NSNotification
  • 单元测试覆盖
  • 支持AppDelegate解耦
  • 支持基于响应链的局部总线

文章:

安装

消息总线:

pod QTEventBus

AppDelegate解耦:

pod QTEventBus/AppModule

基于响应链的事件传递:

pod QTEventBus/UIKit

系统要求

  • XCode 9 +
  • iOS 8+

使用

新建一个类作为事件,实现协议QTEvent

@interface QTLoginEvent : NSObject<QTEvent>
@property (copy, nonatomic) NSString * userId; //可以携带任意数据
@property (copy, nonatomic) NSString * userName; //可以携带任意数据
@end

订阅这个事件

QTSub(object,className)宏的作用是在object的生命周期内,订阅className事件,当object释放的时候自动取消订阅。

//注意eventBus会持有这个block,需要弱引用object
[QTSub(self,QTLoginEvent) next:^(QTLoginEvent * event) {
 NSLog(@"%ld",event.userId);
}];

如果需要在主线程订阅,使用宏QTSubMain

发布事件

QTLoginEvent * event;
[QTEventBus.shared dispatch:event];

详细文档

许可证

QTEventBus使用 MIT 许可证,详情见 LICENSE 文件。

About

iOS事件总线,支持AppDelegate解耦,支持基于响应链的局部总线

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

AltStyle によって変換されたページ (->オリジナル) /