Reading Time: 53 seconds

As a continuation of Part 3: Architecture

Let’s talk about S.O.L.I.D. principles and how they can be applied in Swift.

SThe Single Responsibility Principle

Too strong class


This class works with logic, makes network requests and does navigation work.
So, let’s simplify it and rework it using The Single Responsibility Principle.


OOpen-Closed Principle (OCP)

It’s a principle for object-oriented design first described by Bertrand Meyer that says that “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification”.

Firstcreate protocol abstractions,
create final implementation,
Do not do


LLiskov Substitution Principle (LSP)

Derived classes must be substitutable for their base classes.

swift s.o.l.i.d.

IInterface Segregation Principle (ISP)

Make simple abstractions that clients need.

S.O.L.I.D. principles

DDependency Inversion Principle

Depend on abstractions, not on specific classes/structures.


Abstractions Everywhere! Remember it!

This was a brief guide about S.O.L.I.D. practice in Swift code.

Read moreiOS Best Practices. Part 2: Swift Code Style >>>

Maxim Vialykhvialyx is CactusSoft iOS Tech Lead.

Technical Background
Programming languages: Swift, Objective-C, Java
Technologies and Platforms: iOS, Android, Windows Phone, Amazon S3, Google Cloud, Google APIs, Facebook APIs
Frameworks: PhoneGap, Xamarin
Tools: Invision, SVN, Git, PhoneGap, Titanium, Xamarin, Sketch, xCode, IntelliJ IDEA

  • By filling in the form, you agree to our Privacy Policy, including our cookie use.
  • Hidden
  • This field is for validation purposes and should be left unchanged.

Share article

Let's start a new project together

Contact us