Member-only story

Oversimplifying SwiftUI View Code using ViewState and SwiftUI’s ViewBuilder (Case Study Included!)

Kevin Jonathan
6 min readJan 30, 2024

--

Non-Medium Members can read the full story here.

Let’s say you have developed a pretty complex iOS app with a lot of lines of code, but you are having a hard time to manage the view code because it’s quite messy and hard to read. We can definitely oversimplify it to make it more readable!

Oversimplify? Why?

Why I mentioned “Oversimplify”? Because I removed almost everything (including the use of generics, the complete design pattern, etc) and only included the very basic implementation that you can expand/adjust later on, depending on your needs. Perhaps, I went too far about this oversimplifying. But, don’t worry, I have included the Github repository below for the complete working example app!

Case Study: Todos App

For this article, I will be using a sample todos app that can fetch the todos data from https://jsonplaceholder.typicode.com/ and display the data in a SwiftUI view for the case study. Keep in mind that I am trying to make this app’s code as simple as possible to help everyone understand better how this app’s code simplification works. This is the code snippet for the view part, provided below.

--

--

Kevin Jonathan
Kevin Jonathan

Written by Kevin Jonathan

Just a student intricately weaving personal life experience and technology related stuffs, currently navigating the intersections of life.

Responses (5)