Hello, my name is Mark Nair. And in these lessons you'll learn about methods, mutating methods and overriding methods. When we use the word method we're just talking about a function that we've given to a type. Functions live outside of a type, methods are just functions that live inside of the type. For a good example, let's just build one. So I'm gonna make a struct called city. And inside of the struct, I wanna calculate the distance between a place to another place in kilometers versus miles. So let's just try it. First, we'll make the struct, keyword struct. Then the name of the struct, I'll just call it city. Early braces. Now let's add some properties. I'll have two properties, a name of the city and the distance from Santa Fe in miles. So we'll just say that this is just about the city Santa Fe. So first property. So the name will be of type strength, second property and I'll be very explicit about this. I'll just call it distance from Santa Fe in miles. And I'll make this a double. So far, so good. The struct now is the same thing. A basic struct two properties name and distance from Santa Fe in miles. Now let's add a function inside of the struct to show you how methods really work. Same thing here, keyword func for function. I'm gonna name the function distance from Santa Fe in KM. The idea is I will take the miles that someone types in is the property of distance from Santa Fe in miles, convert that to kilometers. And then I wanna print out the calculation, the result. So let's make that function do the work. So first I'm gonna set up a new constant called distance in KM. I'm gonna make that equal to distance from Santa Fe in miles. Now to calculate miles into kilometers we'll just use a value. I'll multiply this by that value, which is all right. 1.609344, just a constant value. Then I will print. So this will be the name of the city. This is the distance in kilometers from the calculation from line six. This is a very Santa Fe centric. Little bit of code here. Looking good. Now, how do I activate, call, use the method? Well first of all, let's go ahead and say, I'll make a new constant called city one. So here are the properties that we have in the struct. I'll accept that. And I'll just say Albuquerque in the distance from Santa Fe in miles is about 64 miles. All right. So now I have the properties Albuquerque and it's about 64 miles from Santa Fe. But even still we don't have any values here. And if I look on this area over here, I don't see anything. I peek into it. I really just see. It's just these values. To really get to the method, I'll type in the name of that constant then dot. And then I have these pop up and you can see here distance from Santa Fe in miles. And there's a P, which means the property. So there it is. The property on line three. Name is a property. So there's a property in line two but here there's an M that stands for method. Distance from Santa Fe in kilometers. I'll select that. Now, when I run it, the debug council, Albuquerque is 1.2.998016 kilometers from Santa Fe. That's very specific. Let's round that instead. Now, rounding I'll place it right here on line six. I'm gonna round this calculation. So I'll just use the keyword round. I need to put the calculation in parenthesis to make it work. I'll see an error here. Cannot find round in scope. Round is an extension in swift. We need to bring in some help to make sure that our code understands it. And that help is a framework called foundation. Come up here to the top. I'm gonna import, which is another keyword. You can import frameworks and libraries and all sorts of things. But this case I want to import foundation. Now doing that tells our code, now I understand what round is. It's part of foundation. Round is going to round the calculation here and there it is. Albuquerque is 103 kilometers from Santa Fe. Option clicking round shows us this kind of weird thing but we know what this is. We are spitting out a double and in the parameters here we can see exactly what we're dealing with. Let's do something for another city. Now, what we could do is say city one dot. I'll just say name, is now equal to, let's make it. City one dot distance from Santa Fe in miles is equal to, it's above 420, 419 miles. The problem here is I have let city one. I'll change that to VAR. You'll run into that kind of business all the time. I'm trying to change values inside of this, but I said it's a let and I can't. It won't let me, but now I have it. It won't let me, I won't let me. I've changed the values here of the properties. Now let's take a look at our method. City one distance from Santa Fe in kilometers. Boulder is 674 kilometers from Santa Fe. And there we have it. It's a very simple idea. It's just that the function here now lives inside of a type. The type in this case is the struct that we've called city. It could very well be a class. So just think in terms that a method is just a function, just placed someplace else. Thanks for watching. In the next lesson you learn about mutating methods.