‫-: Hi. Within this lecture, we are going to see how
‫we can leverage this init function in order to
‫create these properties without initializing them.
‫So I'm deleting these initializers
‫and I'm going to do this inside of my init function.
‫Okay? So rather
‫than printing musician created I'm just gonna ask
‫for some input in the init function.
‫So I'm going to ask for name init, it'll be a string, okay?
‫And again, an age init.
‫This will be an integer and an instrument init.
‫This will be, again, a string.
‫So what I'm going to do,
‫I'm going to take those values
‫and I'm going to say name is now name init.
‫Age is now age init, Okay?
‫So you're gonna have to say name is equal to name init.
‫Age is now age init.
‫And of course the instrument is again, instrument init.
‫You don't have to say init.
‫You can just go for name.
‫You can just go for whatever variable name you want.
‫I'm just trying to differentiate them a little bit
‫so you don't get confused.
‫Okay? So whenever I create an instance of this class
‫it will ask me for a name and age and instrument.
‫So rather than defining those values
‫after we create the object,
‫now we can do this in the same line.
‫So let me do an example.
‫So if I say Let James and James is a musician
‫it should have asked me there.
‫So let me do comment B.
‫Yep. This is asking right now.
‫So let me do this from the beginning.
‫Okay? So if I do command B, it'll get synchronized
‫as I said before.
‫Now it's giving me an error.
‫It says that you have a missing argument in here.
‫Now if you open parenthesis, you will see that it asks you
‫for a name init, age init, and instrument init.
‫So for name, you can go for James, okay?
‫For age, you can go for 50.
‫And for instrument, you can go for guitar.
‫So now if I print James dot age, it'll give me 50.
‫So that's how you create objects with initializers.
‫Okay? And while we are added,
‫I believe we should learn about enums as well.
‫So enums make our life easier
‫when we try to categorize things.
‫What do I mean?
‫For example, if I want to add a type of musician in here
‫as a property, I can just go and do
‫that with a string right? But rather
‫than doing a string, I'm just going to go for enum
‫and you will see why, why I'm doing that in a clear way.
‫So generally you see enums enumerated type declarations
‫in the top of this project files, okay?
‫So you have to give a name here
‫an enum name, like musician type.
‫And in here you write some categories.
‫For example, our musician can be a vocalist, a guitarist
‫or lead guitarist, right?
‫So write them all.
‫So lead guitar, it would be a vocalist,
‫it would be a drummer, right?
‫And it would be a bassist as well.
‫So maybe you can think something
‫like violinist or something. Okay?
‫So why are we creating this types?
‫We can have done this with strings as well.
‫I'm going to show you why.
‫If I come over here to my attributes
‫I can easily add a new type.
‫I can just say type, okay?
‫And this would be a string, but if I do that
‫my other developer working
‫on this project can write vocal, okay?
‫And the other developer using this class can write vocalist.
‫And even if you are the only one working on a project
‫like this, you can do the same mistake as well, right?
‫You can go for vocal, you can go for vocalist.
‫In some other cases
‫maybe you want to standardize those types.
‫So this is where enums come to play.
‫You kind of standardize the category.
‫So that will leave no room for mistake at all.
‫So rather than saying this is going to be a string
‫I'm going to say this will be a musician type. Okay?
‫As you can see, musician type is a musician type type.
‫So this is an enum, this is not a class
‫but we can actually use this to choose a category.
‫And now we have an error inside of
‫init because we have to ask for a type init, right?
‫So I'm going to go for type init
‫and this will be a musician type rather than string.
‫Now I can come over here
‫and I can easily say my type, this type, okay?
‫is going to be a type init.
‫So right now we have created a category for ourselves
‫and we have assigned it to be a property in our class.
‫So let me do a build.
‫So it'll get synchronized,
‫and once it gets synchronized, as you can see
‫we got another error in here.
‫So it says
‫that you have to add a new parameter here called type init.
‫If you hit fixed, this will be added automatically.
‫So I can hit that here
‫and I can choose one of the categories that we have created.
‫So I can easily come here.
‫I can say, James is a vocalist, for example.
‫And now I can reach this value as well, right?
‫So let me try to print this James dot type.
‫Now I will see the type in the logs as well.
‫So this is how you use enums.
‫This is how you leverage enums in your classes.
‫If you're looking for a way to create categories,
‫rather than doing this with a string,
‫you can do this with enums,
‫and this would be much more efficient
‫much more safer than doing this with a string.
‫So that's all for right now.
‫We are going to stop here actually
‫and within the next lecture
‫we are going to see how we can add some actions
‫some functions to our class as well.