The single responsibility principle in action

Making MVC Less Massive and More Reusable

Implementing a reusable programmatic UICollectionView

Kenny Dubroff
Geek Culture
Published in
15 min readJun 19, 2021

--

Your ViewControllers don’t have to be so massive

In this tutorial, we’ll implement MVC in a way that you may not be familiar with. We’ll create a reusable UICollectionView that’s implemented by its parent UIView and delegates item selection events to a UIViewController. This makes for a very small view controller when compared to the default way we tend to implement them. In addition, it gives you an entirely reusable view that you can invoke with just a single line of code.

This tutorial will cover separating concerns using MVC. If you don’t like MVC, don’t like the fact that I used a view model, or don’t like any aspect of the architecture I propose, feel free to change things to suit your needs. The ultimate point is that views should ultimately be responsible for their own setup as much as is feasible. Another takeaway is that your code should be created to solve a given problem or set of problems, but should also be flexible in order to allow for modification and/or reuse.

At the end of the article, there’s a link to a GitHub repo containing this project in a very unorganized way. There are several challenges to complete — organizing the project is one of them.

--

--

Kenny Dubroff
Geek Culture

I’m a Full Stack iOS Developer with a passion for writing clean, reusable code.