Posts

Showing posts with the label nil coalescing operator

Bob Lee Course Part 8 (lectures 12 to 15)

Image
Next day, next lecture! I literally have 25 minutes now so I will see if I get to a natural end point... Extensions Now I know about these already. Extensions are a way of adding more code to different types. E.g. to Int, I could add a function or something that gives more usability. I can also extend custom types e.g. structs and classes. *Udemy course not loading properly. Going to have to delay start time for now.  Start Time - 15:39  *I only have around 15 minutes for now so will have to continue the entry for later. OK, so the issue here is that you CANNOT have STORED properties in extensions. Right, so in this case, the description property is computed. So this is a cool example of using a new property (computed!) for Int. Squared! So that is everything we can do with extensions. Most of these are later as you can see. So far, that's good. I had to race through some of the using init...

Ray Wenderlich Course Part 9 (up to lesson 79)

Image
So back to the situation of not having much time to write! Am starting this entry now and will continue it on the train. Once I've got functionals and optionals done then that will do for now. Again, I'm going at x 1.5 speed as it's mostly recap. It will be the challenges to really test my mettle! I'm also not going to type examples along - again, it's mostly recap! Functions So just to sum up, you can have no parameters and have code within the curly braces e.g. something to print, or you can have values within the parameters. Within the parameters, you can specify the values or just name the parameter and the type. You can use the _ for an unnamed parameter. The return option -> means you use the return keyword rather than a print function. A little bit in the Q&A from Ray about the distinction between functions and methods: In the old days of programming before Object-Oriented Programming was invented, everyone used to only use functions (usin...

Enumerations & Optionals - final part

Well, I haven't been able to maintain my every/most day but to be fair, two missed days is not the end of the world! Optionals and Enumerations are still pretty fresh in my head. I've used 'Swifty' to consolidate my understanding and go over a few concepts. This next blog should be the last one in the Optional/Enum course.  Raw Values Enums can store different types. Enum members can be populated with default - raw - values. enum Coin {          case penny     case nickel     case dime     case quarter } let coins: [ Coin ] = [. penny , . nickel , . dime , . dime , . quarter , . quarter , . quarter ] func sum (having coins: [ Coin ]) -> Double {          var total: Double = 0          for coin in coins {                  switch coin {            ...