Posts

Showing posts with the label if/else

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

Angela Yu Xcode 12 Course - Part 10 (lectures 113 to 131)

Image
Right so next project! This was one of my favourite ones from before as there was a lot of logic but it was all very accessible too. With this idea, I could make limitless options and stories. Anyway, let's go! Start Time - 18:19 Right so that's the basic look of the app. And there's the decision tree for all the possibilities. Makes sense. OK project file downloaded! Next bit - tag values of the two buttons. Yes there are two options each time. Right, after some fiddly code, here's what I have - if sender. tag == 1 && storyIndex == 1 {             storyTextView . text = story3             topButton . setTitle ( answer3a , for: . normal )             bottomButton . setTitle ( answer3b , for: . normal )             storyIndex = 3                      } else if sender...