SwiftUI Viper (Without UIKit) Project template + example
SwiftUI Viper Architecture - The development paradigm of clean, testable code and modular iOS applications.
This repository contains Xcode templates for quickly creating a project, modules, and services.
VIPER (View, Interactor, Presenter, Entity, Router) is an architectural pattern for building applications. In SwiftUI, this pattern isn't as commonly used as in UIKit, but it can still be employed for code organization with a little trickery, by introducing an entity like ViewState.
What is ViewState used for and what concept is it based on?
ViewState (View State) is similar to @IBOutlet properties and data stored in a viewController, but in the new concept, it utilizes @Published properties and views.
Let's clarify this with an analogy:
Only need execute this command in terminal:
swift install.swift
Download example project built on the basis of this paradigm.
Open Xcode
File > New > Project or press shortcuts โงโN
Select VIPER Architecture
Profit! ๐
โโโ ApplicationViewBuilder.swift
โโโ RootApp.swift
โโโ RootView.swift
โโโ Classes
โโโ Modules
โย ย โโโ Main
โย ย ย ย โโโ Assembly
โย ย ย ย โย ย โโโ MainAssembly.swift
โย ย ย ย โโโ Contracts
โย ย ย ย โย ย โโโ MainContracts.swift
โย ย ย ย โโโ Interactor
โย ย ย ย โย ย โโโ MainInteractor.swift
โย ย ย ย โโโ Presenter
โย ย ย ย โย ย โโโ MainPresenter.swift
โย ย ย ย โโโ Router
โย ย ย ย โย ย โโโ MainRouter.swift
โย ย ย ย โโโ View
โย ย ย ย โย ย โโโ MainView.swift
โย ย ย ย โโโ ViewState
โย ย ย ย โโโ MainViewState.swift
โโโ Services
โย ย โโโ NavigationService
โย ย โโโ NavigationAssembly.swift
โย ย โโโ NavigationService.swift
โย ย โโโ NavigationServiceType.swift
โโโ Architecture
โย ย โโโ InteractorProtocol.swift
โย ย โโโ PresenterProtocol.swift
โย ย โโโ RouterProtocol.swift
โย ย โโโ ViewStateProtocol.swift
โโโ Library
โโโ Swilby
โโโ Assembly.swift
โโโ AssemblyFactory.swift
โโโ DependencyContainer.swift
โโโ ObjectKey.swift
โโโ StrongBox.swift
โโโ WeakBox.swift
โโโ WeakContainer.swift
Open Xcode Project
Select Modules in Xcode Project Navigator
Create new file
File > New > File... or press shortcuts โN
Select Module or Service
Enter Name
After you have created a Module you need to remove the reference on the folder
Highlight the Folder in the Xcode Project Navigator
Press Backspace Key
Press "Remove Reference" in the alert window
Now you need to return your Folder to the project.
Drag the Folder from the Finder to the Xcode project
Profit! ๐
You can use different modules in one project based on the complexity of your screen. One screen - one module.
All your modules should be in the "Modules" folder along the path "Classes/Assemblys/Modules"
โโโ Assembly
โโโ Contracts
โโโ Interactor
โโโ Presenter
โโโ Router
โโโ View
โโโ ViewState
Important! You need to add your Service, Module to the DI Container in the RootApp.swift
container.apply(MainAssembly.self)
// add your module here
Open Xcode Project
Select Services in Xcode Project Navigator
Create new file
File > New > File... or press shortcuts โN
Select Module or Service
Enter Name (if you want to create "Service" you must specify at the end of the name "Service" for example - NetworkService or SettingsService)
After you have created a Service you need to remove the reference on the folder
Highlight the Folder in the Xcode Project Navigator
Press Backspace Key
Press "Remove Reference" in the alert window
Now you need to return your Folder to the project.
Drag the Folder from the Finder to the Xcode project
Profit! ๐
Each service is engaged in its own business: the authorization service works with authorization, the user service with user data and so on. A good rule (a specific service works with one type of entity) is separation from the server side into different path: /auth, /user, /settings, but this is not necessary.
All your services should be in the "Services" folder along the path "Classes/Assemblys/Services"
You can learn more about the principle of developing SoA from wikipedia
โโโ ServiceAssembly
โโโ ServiceProtocol
โโโ ServiceImplementation
Important! You need to add your Service, Module to the DI Container in the RootApp.swift
container.apply(NavigationServiceAssembly.self)
// add your service here
๐ง๐ปโ๐ป Artem Tishchenko Personal Blog
MIT License
Copyright (c) 2023 Artem Tishchenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
BASED ON: Core iOS Application Architecture
If you find this repository useful, you can thank me
Or give a star the repository