• Stars
    star
    428
  • Rank 101,481 (Top 2 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 文件。

More Repositories

1

ios-developer-tools

Tools that every iOS developer should know.
Swift
1,667
star
2

Blogs

一点心得 - iOS,Swift,React Native,Python...
Objective-C
1,593
star
3

ReactNativeMaterials

React Native的中文参考资料,包括开源库,文字/视频资料,相关工具等
704
star
4

PullToRefreshKit

【Deprecated】Pull to refresh in Swift, easy to use, easy to customize(下拉刷新/QQ/淘宝/优酷/雅虎天气/大众点评)
Swift
554
star
5

awesome-rxswift

An "awesome" type curated list of RxSwift library and learning material
Swift
500
star
6

MDTable

A data-driven UITableView framework
Swift
162
star
7

ImageMaskTransition

Elegant image transition between view controllers,support both Modal and Push
Swift
121
star
8

LeoDanmakuKit

An iOS Danmaku Kit (添加纯文字弹幕)
Objective-C
52
star
9

LHPerformanceStatusBar

A status bar to show FPS, CPU and memory usage
Objective-C
51
star
10

WCGradientCircleLayer

Draw Gradient Layer from one color to another
Objective-C
36
star
11

ParallexBanner

【Deprecated】A banner scrollview to show images with parallex effect
Swift
30
star
12

LHNavigationController

像网易新闻那样,支持全屏push/pop的导航控制器(A NavigationController that allow you to push/pop with full screen gesture)
Objective-C
26
star
13

DraggableTableView

【Deprecated】Extension for the UITableView that allows a user to move cells with long press and drop.
Swift
26
star
14

LHProgressHUD

A modern ProgressHUD with wonderful animation
Objective-C
23
star
15

LHCityPickerController

包含所有地级市的城市选择控制器,和大众点评类似
Objective-C
13
star
16

React-Native-Files

A project used to store temp files
12
star
17

SwiftDynamicTableviewHeight

A project about how to do dynamic height with system cell
Swift
12
star
18

LeoMobileDeveloper

1
star