A complete set of primitives for concurrency and reactive programming on Swift
- 1.4.0 is the latest and greatest, but only for Swift 4.2 and 5.0
- use 1.3.0 is for Swift 4.0+
- use 1.2.4 for latest release for Swift 3
Features | |
---|---|
? powerful primitives |
Future , Promise , Channel , Producer , Sink , Cache , ... |
? versatile transformations |
map , filter , recover , debounce , distinct , ... |
✌️ convenient combination |
flatMap , merge , zip , sample , scan , reduce , ... |
? improves existing things |
Key-Value Observing, target-action, notifications, bindings |
? less boilerplate code |
neat cancellation, threading, memory manament |
? extendable |
powerful extensions for URLSession , UI controls, CoreData , ... |
? all platforms |
? macOS 10.10+ ? iOS 8.0+ ? tvOS 9.0+ ⌚️ watchOS 2.0+ ? Linux |
? documentation |
100% + sample code, see full documentation |
? simple integration |
SPM, CocoaPods, Carthage |
- Related articles
- Known users
Communication
Reactive Programming
reactive properties
bindings
- unbinds automatically
- dispatches to a correct queue automatically
- no
.observeOn(MainScheduler.instance)
and.disposed(by: disposeBag)
contexts usage
- no
[weak self]
- no
DispatchQueue.main.async { ... }
- no
.observeOn(MainScheduler.instance)
In Depth
Let's assume that we have:
Person
is an example of a struct that contains information about the person.MyService
is an example of a class that serves as an entry point to the model. Works in a background.MyViewController
is an example of a class that manages UI-related instances. Works on the main queue.
Code on callbacks
- "do not forget" comment x2
- the block will be retained and called even if MyViewController was already deallocated
Code with other libraries that provide futures
- "do not forget" comment x2
- the block will be retained and called even if MyViewController was already deallocated
Code with AsyncNinja
- "do not forget" comment NONE
- the block will be retained and called as long as specified context (MyViewController) exists
- Want to see extended explanation?
Using Futures
Let's assume that we have function that finds all prime numbers lesser than n
Making future
Applying transformation
Synchronously waiting for completion
Subscribing for completion
Combining futures
Transition from callbacks-based flow to futures-based flow:
Transition from futures-based flow to callbacks-based flow
Using Channels
Let's assume we have function that returns channel of prime numbers: sends prime numbers as finds them and sends number of found numbers as completion