Posts

Showing posts with the label mutating

Ray Wenderlich Functions and Types Course - Part 9

Five days between entries is not ideal! But I'm going to crack on. Will try to get 2-3 sessions in during the current week. Let's go! Start Time - 19:50 Installing additional components on Xcode as the mac system has been updated just now... CaseIterable - a protocol used so that you can then access the cases with more functionality. There is a lot going on here! enum Weekday : CaseIterable {     case monday , tuesday , wednesday , thursday , friday , saturday , sunday func advance (by dayCount: UInt ) {     let indexOfToday = Weekday . allCases . firstIndex (of: self )!     } } Weekday . allCases var weekday : Weekday = . sunday So after the CaseIterable bit, we have a method (advance) within the enum. It is using Unsigned Int (UInt). That's supposed to be better as no negative numbers will be involved so this is apparently the better one to use. So even more technical.... enum Weekday : CaseIterable { ...

Bob Lee Course - Consolidation of first 8 lessons!

So it has been several days but that cannot be helped sometimes! The good thing is that I'm in no rush to 'finish' this course. Nor should I be! It's much better to let the knowledge sink in and learn about it at deeper level rather than learning more and more new concepts, which I can't make complete sense of. Something I've been thinking of for a while is - as a teacher - levels of understanding within learning. Something at my school in Dubai is 'Do It, Use It, Own It'. This is essentially a way of setting different challenges, from most basic (Do It) to the deepest level (Own It). Let's say that for a Maths lesson, I am teaching Roman Numerals. I would have the 'Do It' task as recalling numerals up to 100 - something that recalling is basically required for. The 'Use It' level would be to explain why e.g. 49 is XLIX rather than IL. This is obviously more complex. An 'Own It' question would be at a deeper level e.g. look ...

Bob Lee Course Part 5 (lesson 8)

Image
It's been a few days but I've managed to find a bit of time to code! Last time it was about type casting - changing the type of different values and knowing the hierarchy for up/down casting. Interesting stuff, especially as it linked in neatly to optionals and error handling. Today we are starting with 'generics'. Don't think I've ever seen these before so here we go! Start Time - 20:24 Introduction to Generics Code 'smell'. What does that mean? Well it is like something could be up. Universal issues include overusing var instead of let; complex or wordy code that is competitive. Interesting! let gradeScores = [ 4.5 , 3.2 , 9.8 , 4.4 , 7.5 , 8.6 ] For this example, I could print out each element separately OR do a for-in loop. What's better? The for in loop obviously - much more elegant code! func genericFunction<anything>(value: anything ) {     print (value) } So the above is an example of a generic function. ...

Nick Walter Challenges Part 8 (Extensions)

Image
Cracking on with Nick's course. I'll be starting with extensions - I can't actually remember what these are! So it will be interesting to see. Start Time - 18:00 Extensions class Dog {     var name = ""     var age = 0 } extension Dog {     var birthYear : Int {         return 2018 - age     } } let theDog = Dog () theDog . age = 8 theDog . birthYear That was it! It's come back to me. An extension is a way of adding to a previous class etc. But why bother with this - couldn't I just put the extension in the original class? extension String {     var EXTREME: String {         return self . uppercased ()     } } var name = "Josh" name . EXTREME Ahhhh OK I can extend other types too - like strings! Nice! extension String {     var EXTREME: String {         ret...