So, here we're going to add a method.
So, we were going to maybe find a city, return a city by name?
>> Yeah. So, maybe my user taps a city in a list,
and then you wanna get more information about that city,
maybe the population of the city.
So you have to go to your model object that we're doing here and
find that particular city.
And we would look it up by name,
which would be the easiest way right now, I guess.
>> That makes sense.
So it would be find city with name,
and then we pass in name string.
There are probably better ways in Swift to do this,
as we covered in the standard library, ways you can search through a string.
But here to show comparisons with Objective-C, we're just going to iterate
through the array and do string comparison on all the names.
>> And ultimately, if it works it works, right?
>> Yeah. >> [LAUGH] You can get fancy with
a single line of code.
But sometimes a for loop is just less mental gymnastics, so [LAUGH].
>> I agree. >> Yeah.
>> Oh, and just something that we totally missed here.
>> Yep. >> This is the return bad, return type.
This should give you a city, but an optional city because it might not,
the name you're passing may not be in our cities already.
So if we find it we're gonna return the city, if we don't find it,
we're gonna return nil.
>> Like, if I'm looking for Tokyo but my country is Canada.
You would wanna return nil just to indicate that that city doesn't exist
in Canada basically.
>> Yes.
And we covered that in our optionals, so you should know that.
And in Objective-C, the same function is gonna look a bit weird.