Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

Intro

Hi, I am William Jiamin, the creator of youtube channel CodeWithWilliamJiamin and the creator of this website(learn-it-free.com). I am a self-taught iOS developer and I have been developing iOS apps for 10 years. I have been using SwiftUI since it was released in 2019. I have created many SwiftUI tutorials on my youtube channel . I am very excited to share my knowledge with you and I hope you will enjoy this article.

What is SwiftUI?

Well ,if you are new to iOS development, you might be wondering what is SwiftUI? SwiftUI is a new framework that was introduced by Apple in 2019. It is a new way to create user interfaces for iOS, macOS, watchOS, and tvOS. It is a declarative(Don't worry, I will explain this later) framework that allows you to create user interfaces in a very simple way. It is very easy to learn and it is very powerful. It is the future of IOS.

When I first started learning IOS dev, there is no swiftUI. I have to use storyboard and UIKit to develope apps. Believe me, it is very hard to learn. And it is really hard to get the design and restriction right. I have to spend a lot of time to learn it. But now, with SwiftUI, it is very easy to learn. You can learn it in a few days. And you can create a beautiful app in a few hours. The declarative syntax is very easy to understand. And definitely a life saver to get the design and restriction right, quick.

What is declarative anyway?

So , as I promised, I will explain what is declarative. Declarative is a programming paradigm that expresses the logic of a computation without describing its control flow.

OK, I know it is a mouthful. Let's just see the code below:

So, for example ,you want to write some code to make a red circle. In imperative programming, you will write something like this:

let circle = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

but, if you are using declarative programming, you will write something like this:

let circle = Circle()
    .fill(Color.red)
    .frame(width: 100, height: 100)

You just initialize a Circle and set the fill color to red. And then you set the frame of the Circle to CGRect(x: 0, y: 0, width: 100, height: 100). And that's it. You don't need to know how to create a UIView. You don't need to know how to create a CGRect. You don't need to know how to set the background color of a UIView. And you don't need to know the control flow of the code. You just need to describe what you want to do. And the framework will take care of the rest. Just like it's name, you are declaring what you want to do, like a big dictator(Forgive me for the bad joke). And the framework will take care of the rest.

Of course, this is just a simple example. But you can see the difference between imperative and declarative programming. And you can see how easy it is to write code in declarative way. But rest assured, swiftUI can do much more than just creating a red circle. You can create a whole app with it. And it is very easy to learn. So let's get started.