SwiftUI Crash Course
What is SwiftUI?
8m 3s
8m 34s
8m 11s
5m 10s

The course is part of this learning path

Start course
1h 19m

This course delves into SwiftUI, which you can use to create user interfaces for your apps. We're going to cover how to use it, how to create views, and how to leverage it to create responsive apps that work in all screen sizes.

Intended Audience

This course is designed for anyone who wants to:

  • Learn about iOS development and coding
  • Move into a career as an iOS developer
  • Master Swift skills


To get the most out of this course, you should have some basic knowledge of iOS.


Hi. Within this lecture, we're going to see a new concept called Binding. And in order to do that, I'm going to create another file as usual. I'm going to come over here and say new SwiftUI file and I believe this will be our FifthView. So, in this FifthView, I'm going to change our text one more time but rather than changing it constantly, I'm going to take the input from the user. So, we're going to use a text field along with our text as well. So, let me wrap this around the VStack because I'm going to have a text field just under my text. And text field is the actual text field that we have used before in storyboards as well. So, this is where we get input from the user. When you open the parentheses, it will ask you for some parameters. We're going to go for the first one which asks for a title and a text. So, title is actually just a placeholder and the text is the binding string and we're going to see what it is. So, in TextFields, in the text side, I'm just going to say placeholder and it will display this message if there is nothing on the TextField. But in the text, I'm going to create a state variable as before and I'm again going to call this my name, and this time I'm going to give James as my name initially. And after that, we're going to display James over here in the text section. So, this will display my name rather than Hello World! And I'm going to bind my name to the TextField. So, how do I do that, and what does it even mean to bind something? You will see. If you write my name, it will give you an error. It will say that, I'm asking for a binding string and you're just going to... You're just trying to give me a regular string rather than binding string. So, how do we convert something to be binding? You put a dollar sign in front of the variable name. Now it's blinded. So, it means that when we change this TextField value, the state variable will also get changed. And we get to see the change in the text as well, since this is a state variable, it will be re-rendered. So, here we go. Now, we see the James in the text and we see the James in the TextField. So, let me just bring this up a little bit by adding a padding and just increasing the font size a little bit so that we can see it better. As as you can see, now we see the James. Now I want to change this TextField so that this binded variable will get changed as well. So, let me click over here. And you cannot see the keyboard but you can just type with your own keyboard, and as you can see, once I delete and once I add some characters, this changes. So, this is very cool, right? In order to have something like this, in old regular main storyboards, we had to go for delegates and we had to bring in some new functions and everything. Of course, we can reach this result in old way as well, but this time we're doing this just with one line. We're just binding this variable to our text field so that when we change this value, the state variable will get changed and everything showing that state variable will also get re-rendered and we will see the new result, we will see the new value on that text as well. So, this is again one of the cool features of SwiftUI. It may seem a little bit complicated when you compare it with previous methods, like we didn't have this binding and we didn't have this at state before, but right now we have this and once you get to know this, you will love it because you can actually create whatever you want with SwiftUI in less time, in less code and in a more structural way. Now, we have a lot more to learn regarding SwiftUI. In order to do that, I'm going to stop here and we're going to start building an app, it's called favorite book, and we will just learn along the way when we build the app. So, we will get to practice what we have learned so far, and we will learn a lot more things along the way.


About the Author
Learning Paths

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics