Stephen DeStefano Swift 5 Course - Part 3 (Lectures 8 to 11)
Well it's been a good few days but I'm back! No need for more of a preamble than that - straight into functions!
Start Time - 14:06
Functions
These are SELF-CONTAINED. It is best to name what the function actually does.
Syntax - the name, parameters, return bit etc.
Nothing else new here. Bit about the return value and print statement used.
Underscore - placeholder for a constant/var without an actual name.
9 out of 10! Only one that was wrong was a bit of a trick question. OK next!
Returning Multiple Values
So this of course means returning a tuple
All very technical - again, Stephen combines lots of elements - for loops, if statements, optionals...all hard to keep on top off!
Names of return types - optional. Used to improve readability of code.
Argument Labels and Parameter Names
Argument label - used when calling the functions. Better for readability. Swift used the parameter name as the default.
Labels are used on the outside - on the left of the parameter names. These are optional (not that type of optional!).
Use of underscore - again, this will then omit the parameter label when calling the function.
Default values - you can assign values and put these into the code,
Variadic and In-out Parameters
Use of the ellipsis for an undisclosed number of values to go in.
In out - makes it possible to take the value of the parameter, modify the value then update it. inout keyword used.
Have to use variables for the argument not constants.

So the inout keyword is used in the parameter part of the function. It's for changing the value outside of the scope of the function body.
Nested functions - functions within a function.
The one they are in are the global function. Nested ones are hidden by default.
Finish Time - 15:10
Well, that was hard! Lots of complex stuff from Stephen. To be fair I could have been a bit more focussed. Some was familiar but it will take some practice and actual putting into practice.
Start Time - 14:06
Functions
These are SELF-CONTAINED. It is best to name what the function actually does.
Syntax - the name, parameters, return bit etc.
Nothing else new here. Bit about the return value and print statement used.
Underscore - placeholder for a constant/var without an actual name.
9 out of 10! Only one that was wrong was a bit of a trick question. OK next!
Returning Multiple Values
So this of course means returning a tuple
All very technical - again, Stephen combines lots of elements - for loops, if statements, optionals...all hard to keep on top off!
Names of return types - optional. Used to improve readability of code.
Argument Labels and Parameter Names
Argument label - used when calling the functions. Better for readability. Swift used the parameter name as the default.
Labels are used on the outside - on the left of the parameter names. These are optional (not that type of optional!).
Use of underscore - again, this will then omit the parameter label when calling the function.
Default values - you can assign values and put these into the code,
Variadic and In-out Parameters
Use of the ellipsis for an undisclosed number of values to go in.
In out - makes it possible to take the value of the parameter, modify the value then update it. inout keyword used.
Have to use variables for the argument not constants.

So the inout keyword is used in the parameter part of the function. It's for changing the value outside of the scope of the function body.
Nested functions - functions within a function.
The one they are in are the global function. Nested ones are hidden by default.
Finish Time - 15:10
Well, that was hard! Lots of complex stuff from Stephen. To be fair I could have been a bit more focussed. Some was familiar but it will take some practice and actual putting into practice.
Comments
Post a Comment