- Notifications
You must be signed in to change notification settings - Fork795
SwiftUI sample app using Clean Architecture. Examples of working with SwiftData persistence, networking, dependency injection, unit testing, and more.
License
nalexn/clean-architecture-swiftui
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- Clean Architecture for SwiftUI
- Programmatic navigation in SwiftUI project
- Separation of Concerns in Software Design
A demo project showcasing the setup of the SwiftUI app with Clean Architecture.
The app uses therestcountries.com REST API to show the list of countries and details about them.
Check outmvvm branch for the MVVM revision of the same app.
For the example of handling theauthentication state in the app, you can refer to myother tiny project that harnesses the locks and keys principle for solving this problem.
- End of 2024 update: the project was fully revamped to use modern iOS stack technologies
- DecoupledPresentation,Business Logic, andData Access layers
- Programmatic navigation. Push notifications with deep link
- Redux-like centralized
AppStateas the single source of truth - Native SwiftUI dependency injection
- Handling of the system events (such as
didBecomeActive,willResignActive) - Full test coverage, including the UI (thanks to theViewInspector)
- Simple yet flexible networking layer built on async - await
- UI - vanillaSwiftUI +Combine
- Data persistence withSwiftData
SwiftUI views that contain no business logic and are a function of the state.
Side effects are triggered by the user's actions (such as a tap on a button) or view lifecycle eventonAppear and are forwarded to theInteractors.
State and business logic layer (AppState +Interactors) are natively injected into the view hierarchy with@Environment.
Business Logic Layer is represented byInteractors.
Interactors receive requests to perform work, such as obtaining data from an external source or making computations, but they never return data back directly.
Instead, they forward the result to theAppState or to aBinding. The latter is used when the result of work (the data) is used locally by one View and does not belong to theAppState.
Previously, this app did not use CoreData for persistence, and all loaded data were stored in theAppState.
With the persistence layer in place we have a choice - either to load the DB content onto theAppState, or serve the data fromInteractors on an on-demand basis throughBinding.
The first option suits best when you don't have a lot of data, for example, when you just store the last used login email in theUserDefaults. Then, the corresponding string value can just be loaded onto theAppState at launch and updated by theInteractor when the user changes the input.
The second option is better when you have massive amounts of data and introduce a fully-fledged database for storing it locally.
Data Access Layer is represented byRepositories.
Repositories provide asynchronous API (Publisher from Combine) for makingCRUD operations on the backend or a local database. They don't contain business logic, neither do they mutate theAppState. Repositories are accessible and used only by the Interactors.
About
SwiftUI sample app using Clean Architecture. Examples of working with SwiftData persistence, networking, dependency injection, unit testing, and more.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.

