6:13
objective C code has to work understand what C code is.
And C if you have just two quote a quote
that's a string a C string a null terminated C string of characters.
It's non objective C string.
So, Objective-C has this symbol that it understands, the @ symbol,
which generally means you're indicating an Objective-C object.
So, when you put @", and then a string, you're actually creating an NSString,
which is what we want here.
>> Mm-hm, and similarly, for
the @ array, it's just >> Convenience
to know that we are creating NSArray here.
And everything else is more or less similar.
All right so let's create our country.
7:06
If you say so.
>> [LAUGH] >> We should still
have done Antarctica but definitely next time.
>> [LAUGH] Canada [INAUDIBLE]. >> In our unit testing code, maybe,
with an edge case.
>> [LAUGH] I think it will be the bane of this program.
[LAUGH] So, Canada, There it is.
And we're using UTCountry.
And again we have to call alloc So,
it's not too much different here between this example and the previous example.
So, let's move right on to >> I mean,
ultimately what's happening is the same.
We're creating an instance of an object.
It's just, there's a little bit more boiler plate,
like, it goes around the Objective c version.
But, ultimately it's the same kind of idea.
It's allocating memory, setting up initializing the variables and
storing it in a local variable.
>> Mm-hm.
And so finally I guess we want to find the city with the largest population?
>> Sure. [CROSSTALK] Or one by a name maybe?
>> By the name, sure.
Let's do it by the name to give Vancouver a chance here.
>> Okay. >> [LAUGH] So,
if you wanna find Vancouver >> Which would be Canada.
Anyone can just call findCityWithName.
Vancouver.
8:58
It needs a city.
And again, no type reference here.
>> Yeah, we have to explicitly name the types of all these variables too,
because it doesn't interpret.
Like, it can't figure out that Canada is a UT country for example, or
Vancouver is a UT city by what you're assigning to it.
Yeah so. >> [CROSSTALK] that type inference right?
>> And honestly it doesn't seem like cares.
So, here we are telling the system that Canada country.
And that allows us to the class here.
But when you are actually using it, it is really weak in terms of If it cares or
not whether it's actually a country, or if it's just a generic pointer to anything,
and that's why we always have to put in type name as well.
All right, so that's how we call this function.
10:33
>> Right, cause that's what it is.
>> Cuz even when you're doing the sort of dot syntax, and calling our property, what
it's really doing is calling the scatter >> Behind the scenes.
So, if you're just calling together here these do exactly the same thing.
>> Yeah, because before you had to even,
you didn't always have those dot syntax in Objective C.
That's a new thing on the pass book, you know, five, Objective C 2.0,
whenever that came out >> More than five years.
>> More than five, oh my God.
[LAUGH] But, Yeah, so the dot syntax is really just sugar.
It's just a nice way to access that method,
because some people like that dot syntax.
It makes them feel comfortable and happy.
>> Yeah, because imagine if this did not exist.
11:24
But, really, the dots and tags, it's just hides that call to that method.
That's the difference with Objective-C.
Where as Swift is, that dots and tags is more fundamental to the language.
>> Mm-hm.
It works more like, well I wouldn't say more like, but in C++ when you do it,
Dot, again, in C when you do a dot, you're accessing something directly, so, but
in Objective C, the dot is sort of the arrow operator in C++,
where you're dereferencing the memory and then getting a property.
But then, Objective C, the dot can be either the arrow or
the dot, whereas Swift, you just have the dot, which is very good.
12:01
>> Now I see some warnings.
What are these warnings trying to tell us?
>> These warnings are Xcode trying to be nice and
telling us stuff, that our variables are unused, which is true.
We created them and we haven't used them, because it's more of a demonstration.
So, it also gives us different, so Swift has a new feature which, if you don't care
about a variable, You can not give it a name, which is very interesting.
So, you can call this method and
get the return value, but you just don't care about it.
So, you just want to put into a underscore, which we talked about.
And you can do this in function cranrate and such.
But in Objective C you can't do that, so it's just gonna tell you you
haven't used this yet, which probably means you shouldn't be printing.
I'm sure some people, including myself,
have a question of how is this useful if you are just calling.
Is it that this essentially has an effect and that's all you care about?
>> Yeah. So, say this had a side effect.
Which is doesn't.
Here, you can always just call it without an assigned return value.
But this underscore is really more useful as we coded be for
when you're say getting a block which gives you three parameters.
But you only really need one of them.
So, the other two can be underscores.
So, you're expressing clear intent that I'm going to use this and
I'm not gonna use these.
Even though you're gonna give it to me, I'm gonna sign it to the underscore,
which means I'm just not gonna use it.
But you're still gonna give it to me anyways, right?
When Objective C, you can't express that meaning in Objective C.
So if you have a function that gives you five parameters, five variables,
in Objective C all five would be ran out and
you would have to look in the code to see which ones you're actually using.
In Swift you can express that I'm going to just use this one.
Or none of them, and give them like five underscores, cool.
Okay so what we've seen is a basic of Objective C is SWIFT,
there's a lot more to Objective C obviously and
so we'll have links and for anyone who wants to learn more about Objective C.
It's good to have a look, because there's a lot of code out there, and
there's quite a bit in objective C right now, so it might be useful.
But for the remainder of this specialization,
we'll just focus on [INAUDIBLE].
>> And I hope, after seeing this comparison, you're much more happy that we
are indeed focusing on >> I don't know.
I still like Objective-C,
but maybe that's just cuz I've been programming in it for a while.
[LAUGH] So it's still cool.
>> Yeah, no, I definitely urge everyone that's doing LS, eventually you're gonna
have to give yourself an Objective-C, it's unavoidable, really, at this point.
And maybe if, five years down the road, you can avoid looking at Objective-C but
since >> But sense iOS and Cocoa Touch,
the framework we're using, is random in Objective C, like,
lots of the restrictions do surface in Swift and we see them all over the place.
>> Well, I guess if someone wanted to build a simple app
you could actually build that app with Swift.
And we're going to see that throughout this course.
But if you want very advanced functionality, then in those cases,
some of the codes you might actually find online,
or you may want to use, are in Objective C.
So that's something that, again, goes to the fact that this specialization
is geared towards, maybe, the more beginner, moderate type programmers and
app developers, but Very advanced, perhaps should be much more Objective C savvy.
[LAUGH] >> Yeah, and I guess we can just briefly
mention how Swift and Objective C works together in iOS, because
as you can see there are two languages, and can do the same thing in both.
And like Prior mentioned, there's a lot of existing Objective C code out there.
Well, in Outpoint you do Swift they're not gonna Just discard all that code.
So they created many ways, which is out of the scope of our course,
for ObjC and Swift to work together.
As you see, just like ObjC Bridging-Header here which allows ObjC to be used in Swift
and that's And you may run across that in the future in your codes, and there's lots
of resources that will provide the course materials that goes over that topic.