iOS Best Practices. Part 3: Architecture

Maksim Vialykh
2 min readNov 28, 2017

--

As a continuation of Part 2: Swift Code Style

Never believe “let’s do it quickly and then refactor it”

Let’s talk about common architecture design patterns.

We started with VIPER design. Why?
So, it’s the best practise to decompose you system to lot of small single responsibility blocks — it’s simple and don’t require lot of time.
Many people write theoretic materials about VIPER and describe development process with clean architecture like requirement to spent time a lot.

But it’s not true.

Why?

  • First — We can generate a lot of reusable code using Generamba code generator and own templates. *How work with generamba we’ll discover in next articles.
  • Second — When we work with VIPER we develop our application using S.O.L.I.D principies. This means that each component has single responsibility. Components depends on abstractions. Code depend on classes — they are injected in module configurators. As a result we have flexible system that can extend and modify swiftly.
  • Third — All our modules have excellent code coverage quality. This means that we have possibility to detect our code smells/bugs during development and fix it before QA round. This is a big time saver too.

Ok, let’s discover each component.

VIPER — Clean Architecture
  • View — This is a UIViewController which has outlets to views and handles user iteraction. View has 2 protocols.
    View Input —implemented in View Layer and called from Presenter Layer.
    *Display info on View. e.g. showProgress()
    View Output — implemented in Presenter Layer and called from View Layer.
    *Notify presenter about User actions. e.g. addNewItem()
  • Presenter — This is a class which communicates with View, Router and Interactor using next protocols.
    View Output — look at View section.
    Interactor Output — implemented in Presenter Layer and called from Interactor Layer.
    *Notify presenter about updates. e.g. dataDidLoad()
    View Input — look at View section.
    Interactor Input — implemented in Interactor Layer and called from Presenter Layer.
    *Asks for updates. e.g. loadItems()
    Router Input — implemented in Router Layer and call from Presenter Layer.
    *Navigate between modules. e.g. showDetailsModule()
  • Interactor — This is a class that communicates with Presenter and Entities. Interactor have 2 protocols.
    Interactor Input — look at Presenter section.
    Interactor Output — look at Presenter section.
  • Entity — These any data representation like CoreData Entity, Realm Object, etc.
  • Configurator — One more thing.
    VIPER has lots of components that we need inject between.
    Configurator injects layers between them.

This was a small guide about clean architecture VIPER.

iOS Best Practices to be continued…

Part 4: S.O.L.I.D in swift

--

--