ViperArch is a sample iOS project that demonstrates the implementation of the VIPER architecture using Swift and the Alamofire framework.
VIPER is a design pattern that stands for View, Interactor, Presenter, Entity, and Router. It’s an alternative to the traditional MVC pattern that aims to make your code more modular, testable, and maintainable.
VIPER is particularly useful for large-scale projects, as it separates your code into distinct modules that are easier to understand and modify. Each module has a specific responsibility, and the boundaries between modules are clearly defined, making it easier to collaborate with other developers.
The ViperArch project consists of the following components, each located in its own folder:
Model: contains the
Poststruct, which conforms to the
Codableprotocol and represents a post retrieved from a remote API.
View: contains the
PostsViewControllerclass, which is a
UIViewControllersubclass that displays a list of posts retrieved from the remote API. The view also contains a
PostsHeaderViewclass that displays a header for each section of posts, with the user ID of the author of the posts.
Interactor: contains the
PostsInteractorImplclass, which is responsible for retrieving posts from the remote API using the
Presenter: contains the
PostsPresenterImplclass, which acts as an intermediary between the view and the interactor. The presenter retrieves posts from the interactor and provides them to the view for display. The presenter also computes the number of sections and number of posts in each section based on the user ID of the post authors.
Router: contains the
PostsRouterImplclass, which sets up the VIPER components and provides the entry point for the VIPER module.
Service: contains the
APIServiceImplclass, which provide the implementation for fetching posts from the remote API using Alamofire.
To see ViperArch in action, simply open the
ViperArch.xcodeproj file in Xcode and build and run the project. The main view of the app displays a list of posts retrieved from the remote API. Each section of posts is grouped by the user ID of the post authors.
- Xcode 12 or later
- iOS 13 or later
- Alamofire: A Swift-based HTTP networking library for iOS and macOS.
ViperArch is released under the MIT license. See LICENSE for details.
Contributions are welcome! If you have any suggestions or issues with the code, please feel free to create a pull request or issue on GitHub. Thank you!