All Projects → cesarferreira → Swifteventbus

cesarferreira / Swifteventbus

Licence: mit
A publish/subscribe EventBus optimized for iOS

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swifteventbus

Applozic Ios Sdk
iOS Real Time Chat & Messaging SDK
Stars: ✭ 104 (-88.9%)
Mutual labels:  notifications, communication
Nybus
NYBus (RxBus) - A pub-sub library for Android and Java applications
Stars: ✭ 283 (-69.8%)
Mutual labels:  eventbus, pub-sub
Applozic Android Sdk
Android Real Time Chat & Messaging SDK
Stars: ✭ 611 (-34.79%)
Mutual labels:  notifications, communication
Demo Progressive Web App
🎉 A demo for progressive web application with features like offline, push notifications, background sync etc,
Stars: ✭ 798 (-14.83%)
Mutual labels:  notifications
Lnnotificationsui
A framework for displaying notifications similar to Apple's iOS 8 and iOS 9 notifications.
Stars: ✭ 803 (-14.3%)
Mutual labels:  notifications
Mt
tlock, RWMUTEX, Collab, USM, RSem and other C++ templates for Windows to provide read/write mutex locks, various multithreading tools, collaboration, differential updates and more
Stars: ✭ 18 (-98.08%)
Mutual labels:  thread
Taskmanager
A simple、 light(only two file)、fast 、powerful 、easy to use 、easy to extend 、 Android Library To Manager your AsyncTask/Thread/CallBack Jobqueue ! 一个超级简单,易用,轻量级,快速的异步任务管理器,类似于AsyncTask,但是比AsyncTask更好用,更易控制,从此不再写Thread ! ^_^
Stars: ✭ 25 (-97.33%)
Mutual labels:  thread
Laravel Notify
Flexible Flash notifications for Laravel
Stars: ✭ 787 (-16.01%)
Mutual labels:  notifications
Yii2 Telegram Log
Telegram log target for Yii 2
Stars: ✭ 24 (-97.44%)
Mutual labels:  notifications
Microservices Connector
Inter-Service communication framework, support for microservice architecture and distributed system
Stars: ✭ 17 (-98.19%)
Mutual labels:  communication
Angularfire
The official Angular library for Firebase.
Stars: ✭ 7,029 (+650.16%)
Mutual labels:  notifications
Niltalk
Instant, disposable, single-binary web based live chat server. Go + VueJS.
Stars: ✭ 808 (-13.77%)
Mutual labels:  communication
Toot Relay
Relay that forwards web push notifications to APNs, built for Toot!.app but usable for anyone.
Stars: ✭ 18 (-98.08%)
Mutual labels:  notifications
Burnttoast
Module for creating and displaying Toast Notifications on Microsoft Windows 10.
Stars: ✭ 796 (-15.05%)
Mutual labels:  notifications
Yii2 Slack Log
Pretty Slack log target for Yii 2
Stars: ✭ 24 (-97.44%)
Mutual labels:  notifications
Consul Alerts
A simple daemon to send notifications based on Consul health checks
Stars: ✭ 792 (-15.47%)
Mutual labels:  notifications
Dztalkapp
Delphi non-visual component to communicate between applications
Stars: ✭ 23 (-97.55%)
Mutual labels:  communication
Historyinthreads
Firefox addon: Show browsing history in threads. Search keywords the same way as in Firefox History.
Stars: ✭ 5 (-99.47%)
Mutual labels:  thread
Threadandjuc
⭐⭐⭐⭐高并发-高可靠-高性能three-high-import导入系统-高并发多线程进阶
Stars: ✭ 807 (-13.87%)
Mutual labels:  thread
Iris
Convenient wrapper library to perform network queries using Retrofit and Android Priority Job Queue (Job Manager)
Stars: ✭ 17 (-98.19%)
Mutual labels:  eventbus

SwiftEventBus

Language Language Language Language

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

Installation

Cocoapods

pod 'SwiftEventBus', :tag => '5.1.0', :git => 'https://github.com/cesarferreira/SwiftEventBus.git'

Carthage

github "cesarferreira/SwiftEventBus" == 5.1.0

Versions

  • 5.+ for swift 5
  • 3.+ for swift 4.2
  • 2.+ for swift 3
  • 1.1.0 for swift 2.2

Usage

1 - Prepare subscribers

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

SwiftEventBus.onMainThread(target, name: "someEventName") { result in
    // UI thread
}

// or

SwiftEventBus.onBackgroundThread(target, name:"someEventName") { result in
    // API Access
}

2 - Post events

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

SwiftEventBus.post("someEventName")

--

Eventbus with parameters

Post event

SwiftEventBus.post("personFetchEvent", sender: Person(name:"john doe"))

Expecting parameters

SwiftEventBus.onMainThread(target, name:"personFetchEvent") { result in
    let person : Person = result.object as Person
    println(person.name) // will output "john doe"
}

Posting events from the BackgroundThread to the MainThread

Quoting the official Apple documentation:

Regular notification centers deliver notifications on the thread in which the notification was posted

Regarding this limitation, @nunogoncalves implemented the feature and provided a working example:

@IBAction func clicked(sender: AnyObject) {
     count++
     SwiftEventBus.post("doStuffOnBackground")
 }

 @IBOutlet weak var textField: UITextField!

 var count = 0

 override func viewDidLoad() {
     super.viewDidLoad()

     SwiftEventBus.onBackgroundThread(self, name: "doStuffOnBackground") { notification in
         println("doing stuff in background thread")
         SwiftEventBus.postToMainThread("updateText")
     }

     SwiftEventBus.onMainThread(self, name: "updateText") { notification in
         self.textField.text = "\(self.count)"
     }
}

//Perhaps on viewDidDisappear depending on your needs
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    SwiftEventBus.unregister(self)
}

--

Unregistering

Remove all the observers from the target

SwiftEventBus.unregister(target)

Remove observers of the same name from the target

SwiftEventBus.unregister(target, "someEventName")
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].