Giter Site home page Giter Site logo

quickbirdeng / swiftui-architectures Goto Github PK

View Code? Open in Web Editor NEW
666.0 18.0 48.0 344 KB

Three different architectures (Model-View, Redux, MVVM) for using SwiftUI implemented at the example of a chat app

License: MIT License

Swift 100.00%
swiftui swiftui-example swift architecture architectural-patterns swiftui-mvvm redux model-view ios ios-swift

swiftui-architectures's Introduction

SwiftUI Architectures: Model-View, Redux & ViewState MVVM

This repository contains implementations of a simple chat client called QBChat. Each implementation uses SwiftUI while applying a different architecture (Model-View, Redux & ViewState MVVM). More explanation about each SwiftUI architecture example can be found in this blog article. Currently, QBChat is implemented using the following app architectures:

Model-View

The Model-View architecture does not enforce abstraction of business logic from Views similar to the MVC architecture pattern with UIKit.

Redux

In Redux-like architectures, a global state is used to ensure consistency across all Views being kept in Stores. View components can trigger Actions which are interpreted into state changes by a reducer.

ViewState MVVM

ViewState MVVM uses separate ViewModels for each View (if required). Instead of a global state and global actions, ViewState MVVM creates a separate ViewModel interface for each View containing a State and different Inputs.

Author

SwiftUI-Architectures is created with ❤️ by QuickBird Studios.

To get more information on the different app architectures check out our blog post.

Contributing

Open an issue if you need help, if you found a bug, or if you want to discuss a feature request.

Open a PR if you want to add other SwiftUI app architectures to the repository or make changes to the different implementations.

License

SwiftUI-Architectures is released under an MIT license. See License.md for more information.

swiftui-architectures's People

Contributors

devepre avatar maltebucksch avatar pauljohanneskraft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftui-architectures's Issues

SceneStorage, AppStorage,...

Hi, what then would be the best way to manage @SceneStorage and @AppStorage in this architecture? I tried to put it in the viewModel but XCode doesn't seems to like it (Accessing a SceneStorage value outside of being installed on a View. This will always return the default value.), and putting it in the view make it difficult to have logic reacting on it.

Best regards

how to manage binding var

Hi, thank you for this great demo app!
However, I'm wondering how to manage binding var? Like if I want to add
.searchable(text: $someBindingVar) on the list

I can't put a @Published var in the model .searchable(text: $viewModel.someBindingVar) but it is get-only
Or in the state .searchable(text: $viewModel.state.someBindingVar) but it is get-only also

and with this searchable I don't have acces to a onCommit?

AnyViewModel for UIKit + Combine

Hi,
first of all, I wanted to say this is great work!
I was wondering if there is a way to use ViewModel + AnyViewModel also with UIKit views where objectWillChange is not enough to be able to react to viewModel.state changes. Accessing to the projectedValue of the state property would make the state changes available to a UIViewController subscriber.

Possible "direct binding" between ViewModel object and View?

I'm referring to the ViewState MVVM architecture from now.

I'm wondering how to use direct binding between ViewModel and View.

For example NavigationLink is accepting isActive parameter of type Binding<Bool>. I want to control this value through ViewModel instead of View's @State property. That is because only after ViewModel has finished with Input Trigger action, this binding value of ViewModel will be set to true what will cause NavigationLink to proceed.

Another example: how to move @State private var newMessage = "" from the View to ChatDetailState/ChatDetailViewModel? It will ensure that ViewModel will always have latest message value and could react accordingly. As a benefit, .addMessage trigger will not handle message value since it's already in ViewModel.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.