hey guys so what we're gonna do today is
go over an exercise on functions within
mark crisis
iOS 10 and swift through udemy course it
is section to lecture 20 as of this date
and it's exercise on functions so
normally I put this which I will put
this into my I def journey but I know
there are some people who are just
searching you know maybe they want to
follow along with someone else doing
this exact exercise so I figured I'd
make it a standalone video as well but
if you want to see me go through like
all of section two I'm going to make two
separate videos on that I've already
make made quite a few going through you
know different levels of iOS development
learning it storyboards and things like
that so you can check that out on my
channel but I figured I make this a
separate video for for all those who
just want to see this so let's get to
that so the first thing to do create a
new Xcode playground done a create a
function named add that takes two
parameters of type double and returns
the sum of the two numbers so we want to
create a function named add that's
alright add we can name these num1 and
then they said it wants to be a double
so we do like that and then we do num2
you can name whatever you want but
that's just what I want to name this for
sake of argument and then within it what
did I want us to do I want us to return
the sum of the two numbers so we could
do return num1 plus num2
and you don't even call anything so that
should be right right
no maybe not maybe not right what I have
to send this over like this make that a
double like that so that should work
right I don't see that returning
anything well let's go on to the next
deal sometimes this is slow for me so I
just have to keep it moving and then
I'll come back to it a bit so that was
question to complete all right so
question 1 question 2 now push it
through create a function name subtract
that takes two parameters of type
integer
so integers and returns difference of
the two numbers so basically we're just
done the same thing by subtracting let
me just return it seems like ways last
time but subtracting but what do they
want us to do or terms of difference of
the two numbers so oh that's right what
we didn't do is assign numbers to the
actual variables correct see I'm still
having trouble with this reader over
here because it's just let's have a
playground by the soffits do not hello
playground so what we're going to do is
we're going to exit out of this and then
and then I'm going to paste it back in
hopefully that'll fix it so now I
shouldn't have I don't think you should
have anything because we haven't
declared num1 to be any type of number
except for a double
so basically the next thing we do is the
same exact thing but we multiply floats
and then after that we're going to
divide double so let's just hurry up and
do that already so because this is
really not a difficult
and then we're gonna do next is all this
functions all of this what does it say
all of those functions in pass different
values into the parameters ensure they
are producing the correct results is
this a miss I don't know this may be a
misprint
but so basically we're giving all these
numbers okay so it looks like it wants
us to assign these it wants us to
reference or call these functions into a
situation where we are actually
declaring the numbers so we can use var
or let let's just do left but make it
nice and neat let I don't think I can
use add let's do let plus and but these
are doubles so actually just not do that
let's do three point three I think I
have to put equal sign there maybe yeah
okay and now it goes back up and says oh
this is the last thing that I'm wanting
them to equaled within this function we
just do that with all from let -
and make num2 equal seven and we'll see
that this doesn't work because it needs
to be an integer integer to an integer
so if we take these out it works so 8 8
- 7 8 - 3 even if we put a double over
here it won't work because obviously
they're declared to be an integer hasn't
changed yet till I get out of there as
you can see there's errors there's an
error here and just didn't change right
here 3 foot can only hold like so many
bytes it's only it's only so many bytes
worth while the double is is a lot
bigger than a float so normally they say
use a use a double some people would
like to say oh no I want to use a float
because it's gonna use less memory well
it's not worth in the long run I mean if
you need to change that means you'd have
to go back and change the float and the
only reason you need to do that is if
there's an error in your code so
so I think that's it they just want us
to throw values in there make sure it
worked each and every way make sure that
a double worked right or major first of
all I made sure that our function works
right made sure that we declared it
correctly in order for you know two
doubles to come out as a double and in
order for us to only be allowed to put
in doubles there as well as integer
float and double again so that's the end
of this exercise Swift 3 functions I
hope you guys enjoyed it if you haven't
checked out my height up journey yet be
sure to do so if you want to you know
get on this journey with me and I'll
support you guys while y'all support me
and it'll it'll help us get closer to
our goal our end goal and that's to be
an iOS developer one way or another so I
hope you enjoyed it have a good one