‫Instructor: Hi, within this lecture
‫we are going to learn about access levels.
‫So what are those?
‫They define where we can reach the variable
‫or functions that we have created. Okay?
‫We have five of them.
‫It starts with private and it goes down to the open.
‫So, let me start with open and public.
‫We don't generally use them.
‫Why?
‫Because they're not kind of safe to implement.
‫If you make something open, it means that
‫it can be reached from anywhere in the project
‫and it can be changed from anywhere in the project.
‫Public also can be reached from anywhere
‫but they cannot be changed.
‫So, why are we not using them and who uses them anyway?
‫Within the next sections we are going to work with
‫external libraries.
‫So we are going to just download some software kit,
‫development kits as the case to our project.
‫For example, in order to work with a cloud server
‫in the case of Firebase we are going to see
‫how we are going to do that, don't worry about it.
‫But right now know that we are going to implement
‫and download some project files into our own project.
‫And these Firebased developers make their files public
‫so that we can reach them and use them in our own project.
‫But other than that, there is no way,
‫there is not actually a logic to implement public and open.
‫Rather, we are going to work private file private
‫and internal mostly.
‫So private means this is actually private
‫this is special to the class that we have created in.
‫It cannot be reached from anywhere else.
‫So if you want to make it private then you have to
‫be careful because you cannot reach it from somewhere else.
‫And internal is the default one.
‫And file private means you get to reach it from the file.
‫For example, you get to reach it from this musician's
‫dot swift file.
‫Not in the class only, but from this file. Okay?
‫So let me make an example because you will
‫understand it much better this way.
‫For example, let me make this function sync private.
‫So if I make this private, it means that I can only
‫reach this sync function within my musicians class.
‫I cannot reach it from anywhere else in my project.
‫So, let's try, actually I made this private, right?
‫So, can I call this from main dot swift
‫or can I call this function from other
‫classes or other swift files?
‫I cannot do that.
‫If I do command B or if I try to run this,
‫as you can see, it gives me an error and it says that sync
‫is inaccessible due to private protection levels.
‫So James cannot sing right now because I made it private.
‫And in the super musician class also,
‫even though I'm inheriting this
‫I cannot reach the function sync.
‫So if I make this private, they cannot call this
‫sync function from anywhere in my project.
‫So it doesn't make sense to make this private
‫because I'm inheriting this function.
‫I'm using this function in my objects.
‫So, I believe we should delete this.
‫But there will be some cases that you may want to
‫make things private.
‫For example, if you try to come up with a variable inside of
‫your main dot swift or inside of your weave controller
‫and if you're not going to use that variable inside
‫of this another class, for example, you can make it private
‫and you can make it for functions as well.
‫For example, in my musician dot swift
‫let's suppose that I have a test function, okay?
‫And I'm just testing something so I can print out test
‫for example,
‫let's say that we are again working in a big group
‫so I'm developing musicians class and I'm testing something
‫but I don't want anyone to create a musician object
‫and reach the test function.
‫So as you can see they cannot call test from main dot swift.
‫So let me do a command B, as you can see, they can call sing
‫but they cannot call test.
‫So this is good, right? We can make things private
‫if we want to make them really private
‫if we want to use them only within the current class.
‫And we can make it file private if we want to
‫use it inside of that particular file.
‫So, this is all we want to talk about access levels
‫and this is all we want to talk about objective
‫oriented programming.
‫So we are gonna stop here and within the next lecture
‫we're going to create a model and display
‫all of this information in a real app.