Posts

Showing posts with the label Switch

Ray Wenderlich Functions and Types Course - Part 7

Image
Here we go! Tricky to get much done this week as I've been working on an application for a potential promotion at work. This is a big deal - if I do get it, it will mean a substantial difference to me short and long term. If I don't, then it may well be a sign that I need to ease my way away from teaching... we shall see! In the mean-time, back to Catie's course. Still a fair bit to do. Aiming to finish it in a few more entries.  Start Time - 17:48 Switch Statements All of this is fine so far. Enums from before used... enum Month : Int {   case january = 1 , february , march , april , may , june , july , august , september , october , november , december } enum Season : String , CaseIterable {   /// ☃️   case winter   /// 🌸   case spring   /// 😎   case summer   /// 🍂   case autumn } func getSeason (month: Month ) -> Season {     switch month {     case ...

Lynda Course - Swift 5 Essential Thinking (Part 3)

Image
So, predictably, it's been tough finding time this week. Knew it would happen with work becoming busier! So a quick-ish entry now. Next bit of Swift Essentials! Start Time - 20:46 4. Application Control Flow I love this! Probably my favourite aspect of Swift. Got enough time to complete this chapter as it's a short-ish one. var hp = 91 var maxHP = 100 // If statement (<, >, <=, >=, !=, ==) if hp < maxHP {     print ( "Health is lower than the max health!" ) } else if hp <= 50 {     print ( "Health is running seriously low!" ) } else {     print ( "Health is not registered" ) } Optional Binding   One interesting point is that the temporary value is only available within the if/let statement, not outside of that scope though! Another example with multiple values. Optional chaining -  if let _ = isShopOpen , let searchedItem = blacksmithShop [ "Shield" ], le...

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

Image
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 u...