How to Decouple Dependencies in Swift / iOS Projects

Enes Buğra Yenidünya
2 min readAug 25, 2022

If you want to create a modular system for your code, managing dependencies can become an issue. It’s a key point of your design. It’s crucial to decouple dependencies when developing Swift / iOS projects. Your code will be more readable, reliable, testable and of course modular. In this article, we’ll look at how to decouple dependencies in an iOS project.

If you want to create a modular system for your code, managing dependencies can become an issue. It’s a key point of your design. It’s crucial to decouple dependencies when developing Swift / iOS projects. Your code will be more readable, reliable, testable and of course modular. In this article, we’ll look at how to decouple dependencies in an iOS project.

What is a dependency anyway?

Dependency is what makes your specific code blocks dependent on other code blocks. So, your code depends on another part of your project to work properly. These dependencies can be 3rd party libraries/frameworks, manager classes, some modules you create (SPM), etc.

How to make our code independent of other parts of the code base?

As SOLID’s last principle “Dependency Inversion” suggest, “Classes should depend upon interfaces or abstract classes instead of concrete classes and functions.” So, the key is Abstraction here.

In Swift, we can define and confirm a Protocol to make a class abstract. This hides the target class’s implementation details and logic from other classes. Other classes only now what our class is capable of.

--

--

Enes Buğra Yenidünya

iOS Engineer — Freelancer #iOS #swift #mobileappdevelopment #software #apple