Member-only story
Decouple Your Classes in Swift
The MVC Architecture in Swift: A Practical Example
Before we start
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12.1, and Swift 5.3
Prerequisites:
- You need to be able to create a new Swift project, and a Single View Application
Terminology
Coupling: The degree of interdependence between software modules and classes
protocol: A blueprint on methods, properties and requirements to suit a piece of functionality
Coupling
Coupling is the degree of interdependence between software modules, and how closely connected they are.
A low degree of coupling is seen as good design, since low coupling can assist with reuse as well as readability and maintainability.
Coupling Using a Segue for Navigation
If we are trying to move between View Controllers using a Storyboard, we might well use code that has prepare(for:sender)
and use this to pass data to a DetailViewController
.