in General

How SwiftUI can change the way you write views

I’ve been experimenting recently with SwiftUI, whilst I’m not great at it; I really appreciate the fact that its now much easier to layout views without all the un-necessary constraints which usually end up breaking. Further, it seems to be much easier to support bigger devices, landscape mode and yes, even dark mode.

Whilst there are concerns about tableviews (in SwiftUI they are called lists) and how slow they are with a list of a lot of rows and not all the UIKit is 1:1, I do feel it can change the way views can be coded.

One of the principles that SwiftUI tries to evoke into programmers is that the view is a struct; meaning any changes discards the old view and it re-renders. Further, if you want to tie your data to the view, then you can also feed it a struct.

What this means is that view controllers follows more of a MVVM style; rather than baking everything into the view controller.

This has changed the way I write legacy code, I now try to feed views structs which may share some properties with an entity; but they are seperate/abstract, which keeps the dependency between models and views a bit looser.

I think I will spend more time in SwiftUI as it increasingly improves. All the examples I’ve seen online have impressed me to at least experiment with it.