Posts

Showing posts with the label standard library

Treehouse Intermediate Course - Part 5 (Generics 3)

Image
So to save the strain on my eyes, I am going to do several shorter entries today but put them into this one blog. It seems silly to have shorter entries which are all about the same content! Last time, generics was tough. But it was useful stuff! The challenge was tricky and so was the content; I'm going to continue with the current course, then do extra reading wherever necessary. Start Time - 09:55 Class Based Type Constraints So Pasan states that the example is 'trivial'...doesn't bode well! class Shape {}          func centre<T: Shape >(of shape: T ) {      print ( "Called" )     } let testShape = Shape () centre (of: testShape ) So just an example here of creating a class and then declaring the type within the <T: Shape> bit.  It works with inheritance too - if I created a  subclass of Shape it would work.  func centreOf( _ shape: Shape ) {     print...