Jetpack is a lightweight reactive programming library for Swift. It provides tools for creating and composing asynchronous and event-based programs using observable sequences.
- Observable sequences
- Mutable and immutable property wrappers
- Combining and transforming observables
- Threading and concurrency utilities
- Array and 2D array reactive wrappers
- Reactive subjects for broadcasting values
import Jetpack
// Create an observable sequence
let observable = Observable.just(5)
// Subscribe to receive values
observable.subscribe { value in
print(value) // Prints: 5
}
// Create a mutable property
let property = MutableProperty(10)
// Observe property changes
property.subscribe { value in
print(value)
}
property.update(20) // Triggers subscription, prints: 20
// Combine observables
let combined = observable.combineLatest(property.asObservable)
combined.subscribe { (a, b) in
print("Combined: \(a), \(b)")
}
// Transform observables
let mapped = observable.map { $0 * 2 }
mapped.subscribe { value in
print(value) // Prints: 10
}
Observable
: Represents a sequence of values over timeProperty
: Immutable wrapper around a value with reactive capabilitiesMutableProperty
: Mutable version of PropertySubject
: Allows broadcasting values to multiple observers
Jetpack provides utilities for managing concurrency:
observable.dispatch(on: .main) // Observe on main thread
observable.delay(timeInterval: 1.0, on: .global()) // Delay events
Add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/username/Jetpack.git", from: "1.0.0")
]
Contributions are welcome! Please feel free to submit a Pull Request.
Jetpack is released under the MIT License. See LICENSE for details.