Stephen DeStefano Swift 5 Course - Part 7 (Lectures 26 to 31)

So continuing with Control Flow! Going to do approximately an hour now - so that will be the rest of this chapter, then the next one on Strings. 

Start Time - 13:20

If/else

Just a catch up on this - skimming through!



Simple example above. The use of else if as the alternative cases.

Nested if statements - having an if statement with one that follows immediately. Simple.


Switch Statements

Again, I'm happy with this. Has to be exhaustive, is better for situations with numbers.

Using several values for different cases -



And this is with number ranges -



Tuples with switch statements -


Again, straightforward stuff. You just need to do the case with two values (as there are two - cars and weeks). In the above, there are closed values, the wildcard bit (underscore used).

You can also use value binding by creating a value within the case  -



So you then use those temp values that have been binned within the print statements.

Where clause - can be used when there are additional conditions to check.

9 out of 10 on quiz - good enough!

Control Transfer statements

Continue, break, fall, throw....

Ok, so continue tells the loop to stop what it's doing when it gets to a certain point, then start up again after this!

Break - for stopping execution earlier than running the whole thing.

Break can be used within a switch statement - if there's nothing specific to put in there.

Fallthrough - so this is a little vaguer. It means the code will continue running through a switch statement, even if the condition has been met. It runs the code in the next switch case regardless if a match or not!

Labelled statements - do statements.

This is the syntax -
 

8 out of 10 but hard! Tricky stuff this - very technical. But good to learn!

Guard statement

Like an if statement but this ALWAYS has an else clause.



An advantage is that you use the unwrapped optional throughout the code block. So better when working with optionals.

Also good for chaining multiple conditions together. 5 out of 6 in quiz - not bad!

Right, last bit for today - Strings!

Strings

Basics - all fine.



Multi-line string literal - this is cool!



String interpolation, concatenation - all good!

Use of append - seems unnecessary but is possible.

Type casting - can change String to NSString. Not sure when or why!

Count - this is used for counting no. of characters in a String.

Ok, I haven't been paying FULL attention to all of this - some of it was VERY technical....but am back with hasPrefix and hasSuffix methods. These are call - have used before for GoT characters when practising!

Converting, appending - more of the same complicated stuff.

Contains method - could be useful for doing a quiz, or an answer to a question! Or something like that!

Now to do Quiz, then I'm done for now! 17 out of 20 - not bad at all!

Finish Time - 14:29 (1 hour 9 minutes total). 

So a useful productive time, but I feel like I'm clicking my heels a bit with this technical stuff. Without it in context it is probably fairly forgettable. So really, I need to complete the next few chapters quickly, then get into a project! Then be working on my own project so I can actually build and create something - that's where lots is learned! OK, done for now but I will be back later today for completing next three chapters - collections, enums and error handling. Then it will be some stuff about what's new before the projects!



Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)