[go: up one dir, main page]

Skip to content

An extension of devxoul's ReactorKit, specifically designed to work with SwiftUI

License

Notifications You must be signed in to change notification settings

gunoooo/ReactorKit-SwiftUI

Repository files navigation

ReactorKit SwiftUI

Swift CocoaPods Platform

ReactorKit-SwiftUI

ReactorKit-SwiftUI is an extension of devxoul's ReactorKit, specifically designed to work with SwiftUI.

Usage

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)
    }
  }
}

Use Cases

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.

Examples

  • Counter: The most simple and basic example of SwiftUI-ReactorKit

Dependencies

Requirements

  • Swift 5
  • iOS 13
  • macOS 10.15
  • tvOS 13.0
  • watchOS 6.0

Installation

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.

License

ReactorKit-SwiftUI is under MIT license. See the LICENSE for more info.