Bob Lee Course Part 5 (lesson 8)
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. ...