Hello, welcome to the 19th tutorial swift programming series. And in this part we're gonna look at classes. Classes are templates that allow you to define variables the methods, objects can be created of classes which which have all the variables and methods, allowing you to use them. For example, you may have a car class, which is just generic. And you can have several objects of the car classic BMW car class, you could have a Mercedes car class, going even further, which one will be covered in this tutorial, but you can inherit from classes also, you could have a general vehicle class. And then you could have a car class that inherits from the vehicle class, he knows he has the basics of acceleration speed and he pops in my head.
Then you could have a boy inherits from the vehicle class, then from let's say, the car class. You could have classes Dane Harry from that, for example, maybe a BM not yet a BMW or a Mercedes and so forth. Maybe from that one. You even have a classic they inherit from that which could be the model, it depends on how deep you want to go within the application. But again, we're just gonna cover classes and it's been quite a simple car class. So you can see how beneficial classes classes are part of group which is object oriented programming, which swift in obviously, C isn't.
Objective C is, c++ is and most other languages are used nowadays, though, pretty much because it's one of the more it's one of the core fundamentals behind programming. Nowadays, object oriented programming allow in to abstract certain functions and variables and properties into classes and then instantiate objects from it. But so you have to declare a class you use the keyword class and the name of the class car. I want to create two variables speed If you have to put a default value on grid strength, put the LA Rams put 100 and also we're gonna put a function that can be fun damage, not damage the car damage damage car is gonna take a integer cord damage code on or is to simply then do discrim minus equals damage so your takeaway amount of damage received from it's cramped. That's it for the class. Now what we're going to do is actually create a variable for var BMW equals two so we're going to instantiate this class in a car open closed bracket And nowadays been instantiated for do printer line BMW dot drempt and we print that out, it prints out 100.
What we're also going to do is BMW dot damage car rust so I value 20. Then it's got print line properly for print line, BMW does strength again, run it, and in Nashville they typically damaged it. And now it's quite clear what goes on properties. It's sorted out at the wall. So we can do is we're going to create a new variable called var of Honda equal car. And if we crank line on the dot strim run that.
We've got 100 and the reason we've got 180 condition a separate object, it's effort and its variables are separate to the method and variables of the BMW object or any other object of car. That's pretty cool so they can have their own properties. That's it for this tutorial. In the next tutorial we're gonna look at the class constructor. If you have any questions, feel free to message us or support us on a system called ek. The email will be in the description, and comment on this video or just directly message us via YouTube.
As usual, all the required links will be in the description for the source code. And as usual, thanks for watching and hope you have a nice day.