Posts

Showing posts with the label extensions

Ray Wenderlich Functions and Types Course - Part 12

Here we are! This will be to conclude Catie's course. It's been useful to go over the content. The issue is that none of it is project-based - I need to see more in context! The MOST useful way of using the info will be in the consolidation entry to follow this. So here we are, the rest on protocols and inheritance! Start Time - 12:56 Protocols and Extensions Extensions - I know about these already. Extending them to protocols... Using protocols you can say 'composition'. If class inheritance isn't quite working then protocols are the way to go! Extensions can't have stored properties or designated inits. At the moment I don't see the advantage of having extensions for a protocol when all of that could just be in one protocol. You can also extend native types e.g. Ints. This is quite advanced! extension Numeric {     var squared : Self { self * self } } An example of putting in member-wise init.  Challenge! Last one fo...

Lynda Course - Swift 5 Essential Thinking (Part 7)

Last part of the course! I'm going spend around half an hour now on this and the rest tomorrow, if/when needed. Let's do this! Start time - 21:00 Enumerations All of the declaring and creating no problems. I want to see the use of assigning values etc. That bit I'm not so sure about. // Declaring an enum enum GameState {     case Completed, Initialzing, LoadingData } // Storing and switching on an enum value var currentState = GameState . Completed switch currentState {      case . Completed :     print ( "All tasks complete" ) case . Initialzing :     print ( "Init in process" ) case . LoadingData :     print ( "Data is loading" ) } Raw and Associated Values You can do this -  enum NonPlayableCharacters: String {     case Villager     case Blacksmith     case Trader } But no other info - quite limited. Can be access...

Treehouse Intermediate Course - Part 10 (Closures 1)

Image
Yes! So completes the aim to get four consecutive days! I actually enjoyed generics more than I thought - the concepts were so difficult but it was interesting finding out about them. Now onto closures - the area of Swift that I find hardest of all! This is apparently a 146 minute course, so I'll likely need at least 5 or 6 entries for this. 24 separate steps, so yes - similar to generics in terms of length! After that, the other iOS intermediate track (there is some crossover there with the Swift one), has a few other projects and bits. So that will be next! OK, let's go! Start Time - 12:22 Functions as Data A key point already is that closures are not a type. It is more that they are 'anonymous functions'. Simple functions - a recap! func printString( _ string: String ) {     print ( "Printing the string passed in: \ ( string )" ) } printString ( "Jeff" ) We can create a constant/variable and assign a function to it. No ar...