‫-: Hi! Within this lecture,
‫we're going to write our first swift code.
‫So, this is a big thing for us, right?
‫So far we have connected our views
‫to buttonClicked function over here,
‫and, uh, we have our ImageView
‫right below our ViewController.
‫So when you see these curly braces,
‫it means a coding block, okay?
‫So we have a coding block in the class,
‫and we have a coding block inside of this buttonClicked.
‫So we write our codes inside of these blocks.
‫So right now this buttonClicked
‫created a coding block for us,
‫and we're going to write what will happen
‫when a button is clicked inside of this function.
‫And here you see something called viewDidLoad.
‫This is automatically generated for us,
‫as you can see, and this is what
‫will happen when I open the app first.
‫So this is the first time a ViewController is loaded.
‫So if I want something to happen
‫when user opens their app, I write it here.
‫But I don't want something to happen
‫when we first open the app, I want something to happen
‫when I first click the button, right?
‫So I'm going to write my code under this coding block
‫rather than viewDidLoad. We're going to go into the details
‫of viewDidLoad later on. For right now,
‫come over here to buttonClicked
‫and we're going to call the ImageView
‫that we have defined. As you can see, ImageView refers
‫to the ImageView that has been defined by us.
‫If you say, imageView dot, you can see the properties,
‫you can see the methods and attributes
‫of the ImageView. What do I mean by attributes?
‫For example, when we were doing
‫something in the main dot storyboard,
‫we can change, we changed actually the attributes
‫from the attributes pane, right?
‫Now, I can reach all of these attributes
‫and even more from here, from the code.
‫Now, if I say, imageView dot, I can see the attributes
‫like image in here. As you can see,
‫it gives us a description, so this is the image displayed
‫in the imageView. So, if I choose this property,
‫I can just change this, okay, inside of the code.
‫And, again, this is going to change the imageView.image
‫when I write this, so let me show you what else.
‫So, this will ask us to create an UIImage.
‫So, this is kind of, an object type, okay?
‫We're going to need a UIImage type object
‫in order to change this. So I'm going
‫to type UIImage, and open parentheses.
‫So you don't understand what a UIImage right now
‫because you don't know what a class is.
‫And you will understand this code
‫later on very clearly, but for right now,
‫let me write the code and you will see what I mean.
‫If you open parentheses, you will see
‫some different options here. I'm going
‫to go for names, because I'm going to create my image
‫from a name. I already have my metallica2 image over here.
‫If I say, metallica2 here, in the quotation marks, okay?
‫So, open a quotation and this is double quotation marks,
‫not a single quotation, so double quotation marks
‫if I say, metallica2, it will find the metallica2 image
‫in my project. It will convert it to be an image,
‫and it will display this image in my imageView.
‫So, that's what it stands for. ImageView is the object
‫that I have created, so let me run
‫in this simulator by the way, so,
‫while it compiles, I will explain the code one more time.
‫ImageView is the object that I have defined
‫over here. That image, same that change the image attribute
‫and if I click on change, as you can see,
‫the image actually changes to UIImage named metallica2.
‫So if I clicked on the change again,
‫it won't change one more time
‫because it's already metallica2 image.
‫And you may think at this point,
‫how do I make an app that, if I click on this change,
‫it will change the image to metallica1
‫and if I click on that it will change to metallica2?
‫And, we're going to do that later on.
‫Don't worry about that. We're going to see
‫how we can achieve this result,
‫but for right now, you don't know
‫anything about swift yet, so we have
‫to learn the basics first. This is just
‫to get you comfortable with Xcode and congratulations
‫on your first app by the way. You have just written an app
‫in which you can change the favorite band image
‫of yours. So let's stop here and we're going
‫to continue with the next one.