Latest 1.0.1
Homepage https://github.com/NanNanCHN/iOS-OC-EventBus
License MIT
Platforms ios 8.0, requires ARC
Authors

Allows publish-subscribe-style communication between components without requiring the components to explicitly be aware of each other

Features

  • [x] simplifies the communication between components
  • [x] avoids register(in +load or initialization instance later)
  • [x] decouples event senders and receivers
  • [x] avoids complex and error-prone dependencies and life cycle issues
  • [x] makes your code simpler
  • [x] is fast
  • [x] is tiny
  • [x] Thread-safe
  • [x] esay to use

Installation

Cocoapods

pod 'DZEventBus'

then you should click Edit Scheme -> Build -> Pre-actions -> provide build settings from your target -> write script python (eventBus.py path) (project path) (DZEventBus path)

Versions

  • 1.0.1

Usage

1 – Prepare subscribers

Subscribers implement event handling methods that will be called when an event is received.


subscribe
- (void)xxxx:(DZEBxxEvent *)event
{
// UI thread
}

2 – Post events

Post an event from any part of your code. All subscribers matching the event type will receive it.

DZEBxxEvent *xxEvent = [[DZEBxxEvent alloc] init];
[DZEventBus send:xxEvent];

Eventbus with parameters

Post event

DZEBAppLifeEvent *lifeEvent = [[DZEBAppLifeEvent alloc] initWithData:@{@"lifeType":@"active"}];
[DZEventBus send:lifeEvent];

Expecting parameters

subscribe
- (void)applifeEvent:(DZEBAppLifeEvent *)event
{
  NSDictionary *eventData = event.dataDict;
  NSString *lifeType = eventData[@"lifeType"];
}

Unregistering

Will provide in the future

Tips

  1. if you subscribe instance method, DZEventBus will create an instance with alloc init by default
  2. subscribe method will be invoke in main thread
  3. your eventbusEvent should be inherited from DZEBEvent

Latest podspec

{
    "name": "DZEventBus",
    "version": "1.0.1",
    "license": "MIT",
    "summary": "Publish/subscribe event bus optimized for iOS",
    "homepage": "https://github.com/NanNanCHN/iOS-OC-EventBus",
    "authors": {
        "nicodeng": "[email protected]"
    },
    "source": {
        "git": "https://github.com/NanNanCHN/iOS-OC-EventBus.git",
        "tag": "1.0.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "iOS-OC-EventBus-Demo/iOS-OC-EventBus-Demo/DZEventBus/*",
    "requires_arc": true
}

Pin It on Pinterest

Share This