My experience using SwiftUI as the main framework to build iOS apps

Kuldeep Vashisht
3 min readMay 6, 2022

In my last blog, I shared with you’ll about my experience of working as an iOS developer intern for an SaaS based company in Bangalore. I said goodbye to UIKit when I said goodbye to Bangalore and I shifted my focus to the newly launched framework; SwiftUI.
From this February, I have been working with a startup based out of New Delhi. Designing our main app from scratch using SwiftUI, the name of the app we are building is Yogpath Wellness and we’ll be launching our app this month. In short, my experience with SwiftUI has been satisfying and enriching.

Now the longer version, let’s first get the one disadvantage of SwiftUI out, yes it only supports iOS 13 and above and that sucks. Now that it’s out in the open , I can whole heartedly say that it’s a breeze to work on SwiftUI, I almost cannot believe that it’s ‘work’. When I first got my hands on it, I could easily grip it’s way of working and build the design in almost half the time it would have consumed in UIKit. And the one thing that was missing is Autolayout, yep no more putting out fires to deal with it. It’s just gone. Despite of Apple’s continuous efforts of keep resolving problems of Autolayout, they gathered enough courage to just get rid of it. So what do we have now in place of Autolayout in SwiftUI? Nothing. SwiftUI has a completely new layout system designed from the ground up to make things in a unified manner. SwiftUI auto-adjusts the spacings and on top of that I created my custom functions to use percentage height and percentage width with the UIScreen.main.width and UIScreen.main.height modifier.

You can’t talk about SwiftUI without talking about the modifiers, cause it’s blessed with ’em. I will start with what I did in my work. In my company Yogpath Wellness, we have to design the consumer app with more than twenty five screens to start with. And we decided to just not use any sort of UIKit or foundation code, When I started as a noob in SwiftUI, I saw the “var body: some view” in it, and it’s a very simple yet comprehensive thing that SwiftUI uses, it basically says that the body must conform to view protocol in a way that the body must return some view, any view but SwiftUI doesn’t know which one. For example it can be a text view, an image, a VStack etc. You can literally write a Text() after ‘some’ if you are absolutely sure that it’s gonna be a Text view alone. With the recent updates apple made with adding packages in your Xcode project with having the requirement of cocoapods is really a breeze. A lot of high quality package dependencies were already available to work with SwiftUI.

I am trying to show you guy’s the snapshots of some of the work but for some reason I am not able to upload images on medium, hope to add them soon but until then, you’ll gotta bear with me and use some of your imagination skills.

Something which I love the most about SwiftUI is their property wrappers, of all my favourite one is the Environment property wrapper. Imagine you can optimise your app to both light mode and dark mode from the very beginning of your development environment. Environment property wrapper helps you do that, and a lot more. One approach I used is that I made one two environment variables in each view, one for a custom back button and one for getting the them of the device. We could decast the colour scheme based upon the users scheme. It’s so cool to see your colour scheme changing as you change the colour scheme in your canvas.

There is surely much more to learn in SwiftUI and it’s probably gonna take one more WWDC event to fully mature, probably the one in the next month ;) . What I am trying to say is SwiftUI is already mature enough to start building even your more complex applications as it will only get stronger with time. For me, I didn’t really felt the need to looking back into UIKit except the fact that a lot of code snippets are available in it which allows you to not bother to write your code. But procrastination aside, SwiftUI is a lot more efficient than UIKit. So, I even made the most basic functionalities in the app by myself. Cheers to SwiftUI, it’s worth the hype!

--

--