Very simple Observable and Publisher implementation for iOS apps.

Overview

Simple observable

CI License: MIT Platforms Swift Version Twitter

Very simple Observable and Publisher implementation for iOS apps.

Useful if you want to use a bit of simple reactive programming but do not want to add the full RxSwift or use Combine.

Observable

Create an Observable instance providing a default value.

let isLoading = Observable<Bool>(false)

you can assign and read the value of this observable using the value property, for example when using it in a view model

isLoading.value = true

You can bind to the value changes using the bind function, for example in a view controller

viewModel.isLoading.bind { [weak self] isLoading in
    self?.loadingView.isHidden = !isLoading
}

You can also use a version of bind that accepts a keypath

viewModel.isLoading.bind(to: userDetailsView, keyPath: \.isHidden)

Publisher

Publisher is an observable without an initial value. An Observable is used for storing state, a Publisher is used for events.

After you create a Publisher instance

let onError = Publisher<Error>()

you can publish new values to this publisher with the publish method, for example when using it in a view model

onError.publish(ApiError.InvalidCredentials)

You can bind to the value changes using the bind function, for example in a view controller

viewModel.onError.bind { [weak self] error in
    self?.showAlert(error)
}

ObservableButton

ObservableButton can be created in code or used from a storyboard. You can use the ObservableButton to easily subscribe to the tap event

loginButton.observable.tap.bind { [weak self] in
    self?.login()
}

Good to know

You can bind to an observable or an publisher just once. This is not a technical limitation but a design decision.

Boith observable and publisher always call the bind method on the main thread so no need to worry about binding changes to UI elements.

You might also like...
When is a lightweight implementation of Promises in Swift
When is a lightweight implementation of Promises in Swift

Description When is a lightweight implementation of Promises in Swift. It doesn't include any helper functions for iOS and OSX and it's intentional, t

A simple and predictable state management library inspired by Flux + Elm + Redux.

A simple and predictable state management library inspired by Flux + Elm + Redux. Flywheel is built on top of Corotuines using the concepts of structured concurrency. At the core, lies the State Machine which is based on actor model.

Modern thread-safe and type-safe key-value observing for Swift and Objective-C

Now Archived and Forked PMKVObserver will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork o

Define and chain Closures with Inputs and Outputs

Closure Define and chain Closures with Inputs and Outputs Examples No Scoped State let noStateCount = ClosureString, String { text in String(repea

A Swift based Future/Promises Library for IOS and OS X.

FutureKit for Swift A Swift based Future/Promises Library for IOS and OS X. Note - The latest FutureKit is works 3.0 For Swift 2.x compatibility use v

Tempura - A holistic approach to iOS development, inspired by Redux and MVVM
Tempura - A holistic approach to iOS development, inspired by Redux and MVVM

Tempura is a holistic approach to iOS development, it borrows concepts from Redux (through Katana) and MVVM. 🎯 Installation Requirements CocoaPods 🤔

Interactive notification pop-over (aka
Interactive notification pop-over (aka "Toast) modeled after the iOS AirPods and Apple Pencil indicator.

Interactive notification pop-over (aka "Toast) modeled after the iOS AirPods and Apple Pencil indicator. Installation The recommended way is to use Co

Write great asynchronous code in Swift using futures and promises

BrightFutures How do you leverage the power of Swift to write great asynchronous code? BrightFutures is our answer. BrightFutures implements proven fu

A library for reactive and unidirectional Swift applications
A library for reactive and unidirectional Swift applications

ReactorKit is a framework for a reactive and unidirectional Swift application architecture. This repository introduces the basic concept of ReactorKit

Releases(0.0.1)
Owner
Igor Kulman
Building mobile apps since 2011, currently suffering Xcode for iOS / Swift development.
Igor Kulman
Observable is the easiest way to observe values in Swift.

Observable is the easiest way to observe values in Swift. How to Create an Observable and MutableObservable Using MutableObservable you can create and

Robert-Hein Hooijmans 368 Nov 9, 2022
Rx is a generic abstraction of computation expressed through Observable Element interface,

Rx is a generic abstraction of computation expressed through Observable<Element> interface, which lets you broadcast and subscribe to values and other events from an Observable stream.

ReactiveX 23.1k Dec 31, 2022
SwiftUI-compatible framework for building browser apps with WebAssembly and native apps for other platforms

SwiftUI-compatible framework for building browser apps with WebAssembly At the moment Tokamak implements a very basic subset of SwiftUI. Its DOM rende

TokamakUI 2k Dec 30, 2022
SwiftUI-compatible framework for building browser apps with WebAssembly and native apps for other platforms

SwiftUI-compatible framework for building browser apps with WebAssembly At the moment Tokamak implements a very basic subset of SwiftUI. Its DOM rende

TokamakUI 2k Dec 29, 2022
Swift Apps in a Swoosh! A modern framework for creating iOS apps, inspired by Redux.

Katana is a modern Swift framework for writing iOS applications' business logic that are testable and easy to reason about. Katana is strongly inspire

Bending Spoons 2.2k Jan 1, 2023
A simple example of the VIPER architecture for iOS apps

Counter Counter is a simple app showing the basics of the VIPER architecture, a version of Uncle Bob’s Clean Architecture for iOS apps. Counter shows

Mutual Mobile 353 Nov 6, 2022
A New, Modern Reactive State Management Library for Swift and SwiftUI (The iOS implementation of Recoil)

RecoilSwift RecoilSwift is a lightweight & reactive swift state management library. RecoilSwift is a SwiftUI implementation of recoil.js which powered

Holly Li 160 Dec 25, 2022
Open source implementation of Apple's Combine framework for processing values over time.

OpenCombine Open-source implementation of Apple's Combine framework for processing values over time. The main goal of this project is to provide a com

OpenCombine 2.4k Dec 26, 2022
ReSwift is a Redux-like implementation of the unidirectional data flow architecture in Swift.

ReSwift is a Redux-like implementation of the unidirectional data flow architecture in Swift. ReSwift helps you to separate three important concerns of your app's components.

null 7.3k Jan 9, 2023
RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.

About Architecture concerns RxReduce Installation The key principles How to use RxReduce Tools and dependencies Travis CI Frameworks Platform Licence

RxSwift Community 125 Jan 29, 2022