Latest 1.0.0
Homepage https://github.com/hootsuite/emit
License Apache
Platforms ios 10.0, osx 10.12, tvos 10.0
Authors

GitHub license
GitHub release
Documentation

Emit is a simple signals library for Swift. It lets you emit strongly-typed events and you don’t have to worry about disposing of subscriptions. Emit supports emit/subscribe, map, and filter. Which makes it ideal for keeping your code simple.

Emit has been developed for use in the Hootsuite iOS app.

Features

  • Strongly-typed events
  • Mapping and filtering of signals
  • Observable variables

Requirements

  • iOS 10.0+, macOS 10.12+, tvOS 10.0+
  • Xcode 9.0+

Usage

Signal

To create a signal you specify the event type that will passed to the subscription closure. You can also specify Void if you don’t want to include an event.

// Create a signal
let loginCompleteSignal = Signal<Bool>()

To subscribe to a signal you pass an owner. The owner needs to be an object (an instance of a class as opposed to a struct). When the owner gets released the subscriptions stops automatically. You may also pass a DispatchQueue that you would like the closure to be called on, the default is DispatchQueue.main.

// Subscribe to it
loginCompleteSignal.subscribe(owner: self) { result in
    // Handle signal
}

To emit a signal simply call emit with the event value. Note that subscribers will be called on the next run loop of their specified queue.

// Emit an event
loginCompleteSignal.emit(true)

ObservableVariable

Observable variables combine a value and a signal. The signal gets emitted every time the value changes.

let email = ObservableVariable("")

email.signal.subscribe(owner: self) { newEmail in
    // Update UI with new email
}

email.value = "[email protected]" // This will emit the signal to update the UI

Demo Project

See the demo project provided for example usage of the Emit framework.

Installation

Emit can be installed using either Carthage or CocoaPods.

Carthage

To integrate Emit into your Xcode project using Carthage, specify it in your Cartfile:

github "hootsuite/Emit"

CocoaPods

First, add the following line to your Podfile:

pod 'Emit'

Second, install Emit into your project:

pod install

Future Work

We have been very pleased with what we have been able to achieve when with Emit, but there are a few things we have on the wishlist:

  1. Combining signals in ObservableVariable so that only one closure is called. Similar to RxSwift CombineLatest.
  2. Only firing ObservableVariable signal if the value is actually different. Currently it fires on didSet even if the value is the same.

License

Emit is released under the Apache License, Version 2.0. See LICENSE.md for details.

Latest podspec

{
    "name": "Emit",
    "version": "1.0.0",
    "platforms": {
        "ios": "10.0",
        "osx": "10.12",
        "tvos": "10.0"
    },
    "summary": "Emit is a swift Framework to support reactive binding in your iOS apps.",
    "homepage": "https://github.com/hootsuite/emit",
    "license": {
        "type": "Apache",
        "file": "LICENSE.md"
    },
    "authors": {
        "Hootsuite Media": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hootsuite/emit.git",
        "tag": "v1.0.0"
    },
    "source_files": "Sources/*.{h,swift}",
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This