Observable alternatives and similar libraries
Based on the "Events" category.
Alternatively, view Observable alternatives based on common mentions on social networks and blogs.
-
RxSwift
Microsoft Reactive Extensions (Rx) for Swift and iOS/OSX platform. -
ReactiveCocoa
ReactiveCocoa (RAC) is a Cocoa framework inspired by Functional Reactive Programming. It provides APIs for composing and transforming streams of values over time. -
ReactorKit
A framework for reactive and unidirectional application architecture. -
OpenCombine
Open source implementation of Apple's Combine framework for processing values over time. -
SwiftEventBus
A publish/subscribe event bus optimized for iOS. -
PMKVObserver
Modern thread-safe and type-safe key-value observing. -
EmitterKit
an implementation of event emitters and listeners in swift. -
Tempura
A holistic approach to iOS development, inspired by Redux and MVVM. -
NoticeObserveKit
NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. -
RxReduce
Reactive implementation of the state container pattern (like Redux). It is based on the simple concepts of state immutability and unidirectionnal data flow. -
LightweightObservable
A lightweight implementation of an observable sequence that you can subscribe to. -
Notificationz
Helping you own NSNotificationCenter by providing a simple, customizable adapter. -
TopicEventBus
Publish-subscribe design pattern implementation framework, with ability to publish events by topic. -
EasyFutures
🔗Futures & Promises. Easy to use. Highly combinable. -
SSEventFlow
A type safe alternative to NSNotification, inspired by Flux. -
Causality
A very simple event bus for Swift with fully typed messages. -
Tokamak
React-like declarative API for building native UI components with easy to use one-way data binding.
Scout APM - Leading-edge performance monitoring starting at $39/month
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest. Visit our partner's website for more details.
Do you think we are missing an alternative of Observable or a related project?
README
Observable is the easiest way to observe values in Swift.
How to
Create an Observable and MutableObservable
Using MutableObservable
you can create and observe event.
Using Observable
you can observe event, in order to avoid side-effects on our internal API.
class SomeViewModel {
/// Public property, that can be read / observed by external classes (e.g. view controller), but not changed.
var position: Observable<CGPoint> = {
return positionSubject
}
// Or use the helper method Observable.asObservable()
// lazy var position = positionSubject.asObservable()
/// Private property, that can be changed / observed inside this view model.
private let positionSubject = MutableObservable(CGPoint.zero)
}
Create Observer with custom onDispose functionality
In some cases Observables require resources while they're active that must be cleaned up when they're disposed of. To handle such cases you can pass an optional block to the Observable initializer to be executed when the Observable is disposed of.
url.startAccessingSecurityScopedResource()
let observable = Observable([URL]()) {
url.stopAccessingSecurityScopedResource()
}
Model Properties as @MutableObservable
Now mark your binded/mapped properties as observable and export public observable
//Private Observer
@MutableObservable var text: String = "Test"
//add observer
_text.observe { (newValue, oldValue) in
print(newValue)
}.add(to: &disposable)
//Public Observer
var textObserve: ImmutableObservable<String> {
return _text
}
Add an observer
position.observe { p in
// handle new position
}
Add an observer and specify the DispatchQueue
position.observe(DispatchQueue.main) { p in
// handle new position
}
Change the value
position.wrappedValue = p
Stop observing new values
position.observe {
// This will stop all observers added to `disposal`
self.disposal.dispose()
}.add(to: &disposal)
Memory management
For a single observer you can store the returned Disposable
to a variable
disposable = position.observe { p in
For multiple observers you can add the disposable to a Disposal
variable
position.observe { }.add(to: &disposal)
And always weakify self
when referencing self
inside your observer
position.observe { [weak self] position in
Installation
CocoaPods
Observable is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Observable'
Swift Package Manager
Observable is available through Swift Package Manager
.
Swift Package Manager (SwiftPM) is a tool for automating the distribution of Swift code.
It is integrated into the swift compiler and from Xcode 11, SwiftPM got natively integrated with Xcode.
dependencies: [
.package(url: "https://github.com/roberthein/Observable", from: "VERSION")
]
Migrations
1.x.y to 2.0.0
Observable
is nowMutableObservable
ImmutableObservable
is nowObservable
Observable.asImmutableObservable()
is nowObservable.asObservable()
Observable.value
is nowObservable.wrappedValue
Suggestions or feedback?
Feel free to create a pull request, open an issue or find me on Twitter.