‫-: Hi. Following this lecture,
‫we are 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.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 into 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 gonna show you two options.
‫And don't worry, after this section,
‫after we complete the basics of Swift,
‫we are 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 method,
‫simple technique, to write our code and see the outputs.
‫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 are going to go for "Blank"
‫because we are going to create everything from scratch,
‫and you can call your Playground whatever you want.
‫Okay? I'm going to call it "Variables."
‫This will be our first topic,
‫and we are going to see what a variable is,
‫and we are 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 this 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.
‫Okay? So you're importing something.
‫Importing means you're importing a library
‫into this project
‫and you are running something called "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 gonna take some time.
‫So the most basic thing about the Playgrounds:
‫they have to be fast and they have to be efficient,
‫because we are just writing some code,
‫and we are expecting to see the outcome of these 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 is a word,
‫what is a print later on.
‫But just for right now, 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 on the right hand side.
‫And since I am printing this, I will see the result
‫on the lower side of this Playground as well.
‫So this is the print section,
‫and 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 site.
‫For example, I multiply 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, okay?
‫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 Mac OS.
‫I'm not, of course, going to build an app
‫for Mac OS 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 storyboard,
‫or deal with the simulator at all.
‫So if you choose the Mac OS
‫you can come here, choose "Command Line Tool," okay?
‫That's what we are going to create here.
‫And we have to give you the product name one more time.
‫So I'm going to say "CommandLineVariables" over here,
‫but I'm not going to write any code in here.
‫I'm not going to explain all the section
‫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++ code
‫in here as well, but we are not gonna do that.
‫But rather, we are just going to go
‫for 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 view controller.swift
‫or app delegate or scene 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.
‫Yeah, 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 and capabilities.
‫And here you go.
‫It doesn't see my account here,
‫so it doesn't see my 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 Xcode 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 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 a 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 Playground.
‫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.
‫Okay? So you can create new variables
‫like this in here as well.
‫You can see something like this.
‫You can say where my number is four times four
‫and print (mynumber).
‫And if you just run this, you will see the same results.
‫So we are seeing 20 in here,
‫and we will see the same thing in here as well,
‫if we run this.
‫Okay? As you can see, we see 16
‫because, yeah, I said four times four, but it's working.
‫So choose one of them.
‫Choose either of them, okay?
‫And if it's working, go with the Playground.
‫If it's not, go with this there, but, okay.
‫So we will stop here.
‫And following the next lecture, we are actually
‫going to start learning about what a variable is.
‫And we are going to start with the basics of Swift.