Posts

Showing posts with the label protocols

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...

Ray Wenderlich Functions and Types Course - Part 11

Image
OK! This is probably going to be the penultimate part. Maybe last part as I have a good hour so we'll see how far I get. Onwards with protocols! Start Time - 17:00 Initializers This is a pretty lengthly tutorial! Always useful to see this in action. Installing additional Xcode components...will follow along with video without actual coding until that's ready. So the super.init is for the superclass. That needs init. Init phases Phase 1- init all stored properties. From bottom of the hierarchy upwards. Phase 2 - use anything that has the use of self. Two phase init! Then the object is ready to use. If you tried creating an object without declaring the value of the sports array an error would come up. So you an give a default value for that in the class....OR, much better, have another way to init! Use of required rather than override. But required needs to be in the super class. Or the base class. Designated inits. They need to call super.init. So we...

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...