[MUSIC] Okay, so is there another function that we could now make? Something that would perhaps go through the cities by population? >> Yeah, should we give out a shot? >> Yeah. >> So, so, this is what we were saying before as sort of the city with the largest population, right? And we're gonna assume that countries always have cities. [LAUGH] >> Okay, and our design document will say every country must have at least city. I mean, you may want the biggest city, right? But the interesting thing is, since this doesn't have to be like, a method, right? It could be a property. Like, a getter, it could be a computer property in Swift, which we've talked about. Because you only have to get it, you'll never set the cityWithLargestPopulation. >> Yeah. And you don't have to pass any parameters [CROSSTALK] to get that back. >> Yes, so in Swift we do that like this, cityWithLargestPopulation, and then we can simply specify together. And we don't even have to give the type since we'll let it know. And what we're gonna do here is do a for loop. >> Yeah. >> Again, and then- >> We're good at that. >> We're really good at that. Population equals zero to start off, and then we're just gonna cheat and copy this for loop up here. We need another variable there, city. >> Yeah, you have to store in the City you're gonna return. >> Yep. >> Cuz you're gonna go through all of them first, right? >> And, should we initialize that to the first city? That could work. But, it probably should be optional. City. Since that, we don't have a city? And then in our for loop. If city.population is greater than the current maxPopulation, we're gonna set city = city, question would be optional. [LAUGH] >> We're gonna not make it optional. And it probably gonna complain where city equals to city. This is not good either because our variable the same. >> So we just call it biggest city or resultsCity. >> Largest city. >> Largest city, okay. >> Largest city of the city. And the maxPopulation is equal to the city's population. So at the end of all this we'll share we have a city. >> So, we'll return the largestCity. >> Now it should stop complaining. No it won't, cuz computer properties must have an explicit type. And it may not be initialized. So we're gonna set it to the first city. >> Yeah. >> [CROSSTALK] Assume that if there's at least one city then that will be the biggest city. >> So here we have a variable, a computed variable that returns a city, and it always goes through all our cities and looks for the largest one. And now we're gonna do the same thing in Objective-C, which means we would create a read-only property for this. >> Yeah, so Objective-C, you can add methods that will be methods like computed properties by just giving them the same name as your property. It is pretty much by convention. It is not like it is really checked. As long as you give it the same name then it becomes a setter or getter for the properties if it has the correct sort of method signature I guess. >> Largest population. >> So, if we create a method called cityWithLargestPopulation, then that will be the getter for that property. >> It's also because the properties do a bit more behind the scenes in Objective-C than they do in Swift. When you define a property, it's already creating the getters and setters for you. Like, the ones with the same name. And then what, and then as we're gonna do right now, when you actually sort of, when you want to write the setter what you're really doing is you're overriding the setter that's been created for you. When you do the property, it creates both a setter and a getter for you, but since ours is a read-only property, it will only create this setter. And since our getter here is special, we want to find the maximum one. We're gonna override it here and sort of try to do the same thing in our Swift class, which is define the largest max population equals zero, and then you're gonna- >> So the idea of computed properties isn't really that different in Objective-C. It's just that, in Objective-C, you're creating an explicit method as the getter or, you know in another case you might be creating a setter. It still looks like a regular method an Objective-C method. Where as in swift it has a bit more of a special syntax, it's more integrated with the property definition itself. >> Mm-hm. The cities population greater than the max population. Did it again. Largest city. I'll reset the largest city, city and set, city's population at the end of all this, return the largest city. All right. >> And because Objective-C doesn't care whether it's nil or not, it doesn't have any idea of optional types, it didn't really give you any complaints about setting that value to some default, it just accepts it as being nil or not, it doesn't matter. >> Yeah, because here there's a chance that if there's no cities, then largest city will not be initialized. But Objective-C lets us return that anyways, whereas Swift didn't allow us to do that. >> Yeah. >> Yeah, so there's maybe a little bit difference here, and it shows us how Swift is safer as a language.