Swiftpack.co - geekaurora/SwiftUIRedux as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by geekaurora.
geekaurora/SwiftUIRedux 1.2.3
🚀Comprehensive Redux library for SwiftUI, ensures State consistency across Stores with type-safe pub/sub pattern.
⭐️ 18
🕓 3 weeks ago
.package(url: "https://github.com/geekaurora/SwiftUIRedux.git", from: "1.2.3")


Carthage compatible Swift Version License

Comprehensive Redux library for SwiftUI.

  • Keep State consistent across Stores by type safe pub/sub pattern with Reducers of RootStore.
  • Waterfall Action propagation flow from root to State subtree.

Unidirectional Data Flow

  • RootStore/Dispatcher: Propagates domained actions

  • Reducer: Subscribes to RootStore and reduces Action to generate new state

  • Action: Action driven - more loosely coupled pattern than Delegation pattern

  • State:

    • Reduces Action and outputs new State
    • Waterfall reduce flow: propagates Action to children nodes via State tree


  • Efficient tree diff algorithm, no more imperative manual update code.

Usage Example


struct FeedListView: View {
  @ObservedObject var state = FeedListState()
  var body: some View {
    List {
      ForEach(state.feeds, id: \.diffId) { feed in
        FeedCell(feed: feed)


public class FeedListState: ReduxReducer, ObservableObject {  
  @Published var feeds: [Feed] = []
  public override func reduce(action: ReduxActionProtocol) {
    // Propagates `action` to the substate tree.
    // Setting `self.feeds` with new feeds triggers list UI reloading 
    // and SwiftUI will diff efficiently based on list identifier.
    feeds = feeds.map { $0.reduce(action: action) }

Dispatch FeedLikeAction

dispatch(action: FeedLikeAction(feed: feed))

Reduce FeedLikeAction

public struct Feed {
  public var diffId = UUID()
  public let feedId: Int
  public let title: String
  public var isLiked: Bool { didSet { diffId = UUID() } }     

extension Feed: ReduxStateProtocol {
  public func reduce(action: ReduxActionProtocol) -> Self {
    // Makes the deep copy of self.
    var feedCopy = self    
    switch action {
    case let action as FeedLikeAction:
      // Reduces the `FeedLikeAction`.
      if feedId == action.feed.feedId {
        feedCopy.isLiked = !action.feed.isLiked
    default: break
    return feedCopy


Stars: 18
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.


Related Packages

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics