Code Monkey home page Code Monkey logo

qteventbus's Introduction

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

qteventbus's People

Contributors

leomobiledeveloper avatar

Watchers

ifshyse avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.