Options for Writing

Contents

keyboard_tab

The course is part of this learning path

Options for Writing
Overview
Difficulty
Intermediate
Duration
2h 50m
Students
4
Description

This course will provide you with a comprehensive understanding of the fundamentals of Swift. We're going to learn about variables, constants, arrays, dictionaries, sets, if statements, and more! 

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

Prerequisites

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

Transcript

Hi, following this lecture, we're going to start learning about the Swift basics. And in order to do that, I actually need something very simple. I don't need any main that storyboards. I don't need any simulators, because I won't be building any user interfaces. I won't be just displaying those user interfaces in my simulator. I just need a very basic way to write Swift code and see the outputs without giving too much thought in the user interface or without having to run simulator every time and wait for it to compile and build and show me the user face and stuff. And in order to do that, I'm going to show you two options and don't worry after this section, after we complete the basics of Swift, we're going to go back to that as well. We're going to create user interfaces, we're going to build apps, we're going to test them in the simulators. 

All the course will be based on this practice. However, in this section, in the basic section we don't need that. We just need a simple methods, simple technique to write our code and see the output. First one is to create a playground and that is the common solution in order to learn about basic swift operations. So, as you can see we can explore new ideas quickly and easily in the Playground. So, when you click on this, it will ask you for a template again. And of course we're going to go for a blank, because we're going to create everything from scratch and you can call your Playground whatever you want. I'm going to call it Variables. This will be our first topic. And we're going to see what a variable is and we're going to create this and save it in whenever, wherever I want. I'm going to go for Desktop or I'm going to go for iOS Complete folder, in fact, and you can just choose it over here as well. I'm going to save every Playground that we are creating in my iOS Complete folder. And later on, I'm just going to share all of those things for you. So, let me create actually a new Playgrounds folder and save these Playgrounds in my Playgrounds folder so that I can zip them and share with them easily. So, here we go. When you first create the Playground, it shows you something like this. 

So, you're importing something. Importing means you're importing a library into this project and you're running something called as str. So, this is a variable actually and where is the keyword to define a variable. We will see what it is later on. If you click on this play button over here, it will run this playground. If you're doing this for the first time, and I believe this is my first time on Xcode 11 for Playgrounds, it's going to take some time. So, the most basic thing about the Playgrounds, they have to be fast and they have to be efficient, because we're just writing some code and we're expecting to see the outcome of this codes fast. If you get stuck in Playgrounds, if this doesn't work for some reason, I will show you another option, because sometimes students experience some difficulties with the Playground. It should be like this. You have to see the output on the right hand side of this Playground. So, if you don't see it, you can try to close this Playground and open it again and hitting the play button one more time. Because it should display these variables very fast actually. 

So, let me create another one. So, you can just write it like me and I'm going to explain what it is about, what is a print later on, but just for right now I know that I'm creating a variable and I'm trying to print it. So, if I click the Play button, I will see the result on the right hand side. And since I'm printing this, I will see the result on the lower side of this Playground as well. So, this is the print section and the right hand side is where we get the output of our code actually. So, this is the logic of Playground. So, you write some codes and you see the results on the right hand side. For example, I multiply 10 by 10 times five and I can see the 50 instantaneously on the right hand side. So, if this is working out for you, that's great. So, you don't have to go for the second option at all, because Playground is actually better and I'm going to explain everything in the Playgrounds as well. But I have come across some situations, students could not start Playgrounds whatever they try. So, they try to close this, they try to restart their computers, they try to delete the Playground and create it again, but it won't start. 

So, if you come across a situation like this, I'm going to show you a second way. And let me show you the second way. Let me go over here to Xcode and say new project. Rather than Playground, I'm going to go for a project. But rather than IOS, now I'm going to create something for macOS. I'm not of course going to build an app for macOS in this at this moment, but I'm going to create a very simple project in which we can write code and show the output instantaneously again without having to deal with the main story border, deal with the simulator at all. So, if you choose the macOS, you can come here choose command line tools. That's what we're going to create here and we have to give it a product name one more time. So, I'm going to say command line variables over here, but I'm not going to write any code in here, I'm not going to explain all the sections in command variables, but I'm just going to show you what it is. 

So, here you can choose Swift and as you can see we can write C or C++ called in here as well, but we're not going to do that, but rather we're just going to go for a Swift and create our project. And as you can see this creates a project just like as we did before, but rather than having a weave controller.swift or app delegate or seen delegate, we only have something called main.swift. So, this is a basic Swift file in which we can write code and when we play this, when we run this here using my Mac, it will just run the code and display the results for me. For some reason I'm getting an error message. Let me see. As you can see, I'm not connected to my Apple ID, even though I suggested you to go and do this in your signing and capability section. Apparently, I didn't do that. So, let me go to signing capabilities and here you go, it doesn't see my account here. So, it doesn't seem see my Apple ID. So, this is very easy to fix. If it's not shown, if it's not chosen for you, just choose it and say sign in and then later on you can just give your Apple ID password over here so that it can connect you to your export project. And I believe this is not an issue for you because you have done this in the previous section for right now it's an issue for me. So, I'm signing in with my Apple ID and it's going to assign my Apple ID to Xcode project and this will be okay then. 

So, right now I'm here signed in, let me go to my main.swift and try to run this one more time and the errors will go away. And as you can see now I will get the log, I will see the output of this print. As you can see, I see the output over here on the right hand side bottom. So, if I do something like this, now I have to print this rather than seeing on the right hand side, because right now we don't have that kind of capability in here. So, I'm going to wrap this around the print and if I do that it will just print the result for me in here like this. So, you can use this technique or you can use the Playgrounds and I suggest if it is working for you, you use the Playground, because it's simpler. You don't have to write print every time in order to see the results. So, you can create new labels like this in here as well. You can see something like this, you can say for myNumber is four times four and print myNumber and if you just run this, you will see the same results. So, we're seeing 20 in here and we will see the same thing in here as well if we run this. As you can see, we see 16. Because I said four times four. But it's working. So, choose one of them, choose either of them. And if it's working, go with the Playgrounds. If it's not go with this there, but okay. So, we will stop here and following the next lecture, we're actually going to start learning about what a variable is and we're going to start with the basics of Swift.

 

About the Author
Students
198
Courses
55
Learning Paths
3

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