SwiftUI Clean Architecture with Rorty App

Mesut G.
5 min readMar 13, 2022

--

If you want to check directly the project before continuing reading the introduction, you can do by accessing the following link:

I had previously developed the same project as native android and jetpack compose. If you want to take a look, you can find it here.

Native Android Rorty App:

Jetpack Compose Rorty App:

Introduction

I built an iOS SwiftRorty Application(Rick And Morty) to reinforce what I’ve learned so far and to improve myself.

SwiftRorty focused on the scalability, testability and maintainability written in Swift, following best practices using SWIFT-UI.

What Did I Develop

The project presents a modern, approach to iOS application development using Swift and latest tech-stack with Swift UI.

The goal of the project is to demonstrate best practices, provide a set of guidelines, scalable and maintainable. This application may look simple, but it has all of these small details that will set the rock-solid foundation of the larger app suitable for bigger teams and long application lifecycle management.

For this project I used the Clean Architecture. I divided the development into two phases. The first set of MVP Features:

  • Splash
  • Home
  • Characters
  • Character Detail
  • Favorites
  • Settings

I developed the application up to the 1st stage but it is not finished yet. If everything is finished/previously on time, I will make a second set of features. The second set of properties would be:

  • Character locations on Character Detail
  • Search or Filter
  • Settings add some features

Screenshots

First
Second

Environment Setup

In order to be able to build the application you’ll need XCode version 13.2.1

Application structure

One of the key benefits of modularization architecture is supposed to be clear navigation throughout the app and source code. Looking at the root folder of the project, the following structure becomes clear.

Project Structures

- Presentation Layer

The presentation which is needed to create the features. It’ s iOS specific and contains view pages, view models and so on. It also contains a service locator to manage dependencies, but you can use Resolver if you prefer. I used it.

- Data Layer

The :data contains the implementation of the abstract definitions of the domain layer. Can be reused by any application without modifications. It contains repositories and data sources implementations, the database definition and its Core Data, the network APIs definitions, the definition of repositories, some mappers to convert network API models to database models, and vice versa.

  • The :data:model contains the definitions of ui model, network response and entity classes.
  • The :data:local contains the definitions database, caching operations using Core Data.
  • The :data:remote contains the network operations defining API endpoints using Combine.
  • The :data:repository contains the exposing data to the domain layer

- Domain Layer

The :domain contains the definitions of the business logic of the app, some mappers for use in ui, and the definition of the use cases. This is the core layer of the application. The domain layer is independent of any other layers domain business logic can be independent from other layers. This means that changes in other layers will have no effect on domain layer eg. screen UI (presentation layer) or changing database (data layer) will not result in any code change within domain layer.

Components of domain layer include:

  • usecase: They enclose a single action, like getting data from a database or posting to a service. They use the repositories to resolve the action they are supposed to do. They usually override the operator invoke , so they can be called as a function.

- Core Layer

The core layer contains different utilities that can be used by the different modules and base structures. Also the definitions of some extension methods.

- Component Layer

The component layer is responsible for common view components that using app.

Tech Stacks

This project uses many of the popular libraries, plugins and tools of the iOS ecosystem.

  • MVVM — the view model is responsible for exposing (converting) the data objects from the model in such a way that objects are easily managed and presented.
  • Resolver — Dependency Injection library.
  • Combine — Customize handling of asynchronous events by combining event-processing operators.
  • Core Data — Persist or cache data on a single device, or sync data to multiple devices with CloudKit.
  • Lottie — JSON-based animation file format that enables designers to ship animations on any platform as easily as shipping static assets.
  • Paging — The Paging Library makes it easier for you to load data gradually and gracefully within your app’s List.

Code Analyze Tools

  • SwiftLint — A tool to enforce Swift style and conventions.

How Can You Contribute?

Full Project

You can access the source code of the project from the link below.

Thanks 🚀

I hope it helps you. If it is useful to you, you can clap this article and follow me for such these articles.

Happy and healthy coding!

Que tengas un buen día, continuará 😊 🏄‍🚀

--

--

Mesut G.
Mesut G.

Written by Mesut G.

Hola everybody, Sharing Software Development Experience, focus on Mobile. https://developersancho.medium.com/subscribe Continue as long as

Responses (2)