Hey there, awesome developer! 👋 Welcome to CombineStore, the coolest way to manage state in your SwiftUI apps using the power of Combine! 🎉
CombineStore is like a magical 🧙♂️ toolbox for your Swift apps. It helps you keep your app's state neat and tidy, making your life easier and your code more awesome!
- 🧘♀️ Zen-like state management
- 🔄 Reactive updates with Combine
- 🎭 Action-based state mutations
- 🧪 Easy testing (because who doesn't love writing tests? 😉)
First things first, let's add some CombineStore magic to your project! ✨
Add the following URL to your project's Swift Package Manager dependencies:
https://github.com/boska/CombineStore.git
-
Define Your State
struct AppState { var counter: Int = 0 var username: String = "" }
-
Create Actions
enum AppAction { case incrementCounter case setUsername(String) }
-
Implement Your Store
final class AppStore: CombineStore<AppState, AppAction> { override func reduce(_ state: AppState, _ action: AppAction) -> AppState { var newState = state switch action { case .incrementCounter: newState.counter += 1 case .setUsername(let name): newState.username = name } return newState } }
-
Use in SwiftUI
struct ContentView: View { @StateObject private var store = AppStore(initialState: AppState()) var body: some View { VStack { Text("Counter: \(store.state.counter)") Button("Increment") { store.dispatch(.incrementCounter) } } } }
We love contributions! If you have any ideas, just open an issue and tell us what you think.
CombineStore is available under the MIT license. See the LICENSE file for more info.
- Thanks to the Swift and SwiftUI teams for their awesome work!
- Shoutout to the Combine framework for making reactive programming a breeze!
Made with ❤️ by [Yang Lee, STRV]
Happy coding! 🚀👨💻👩💻