ReactorKit-SwiftUI is an extension of devxoul's ReactorKit, specifically designed to work with SwiftUI.
let reactor = MyReactor() // A reactor is the same as in ReactorKit.
let view = MyView(reactor: reactor)
struct MyView: ReactorView {
var reactor: MyReactor
func body(reactor: MyReactor.ObservableObject) -> some View {
// this is called when the state updates.
VStack {
Button("Hello") {
reactor.action.onNext(.helloTapped)
}
Text(reactor.state.title)
}
}
}
ReactorKit-SwiftUI is useful in the following scenarios:
- When you want to convert your existing ReactorKit-based project to SwiftUI while keeping all business logic unchanged.
- When you are using RxSwift and want to apply SwiftUI in your project.
- When you want to use both ReactorKit and SwiftUI together seamlessly.
- Counter: The most simple and basic example of SwiftUI-ReactorKit
- ReactorKit >= 3.0
- Swift 5
- iOS 13
- macOS 10.15
- tvOS 13.0
- watchOS 6.0
Podfile
pod 'SwiftUIReactorKit'
Package.swift
let package = Package(
name: "MyPackage",
dependencies: [
.package(url: "https://github.com/gunoooo/ReactorKit-SwiftUI.git", .upToNextMajor(from: "1.0.0"))
],
targets: [
.target(name: "MyTarget", dependencies: ["SwiftUIReactorKit"])
]
)
ReactorKit-SwiftUI does not support Carthage.
ReactorKit-SwiftUI is under MIT license. See the LICENSE for more info.