Posts

Showing posts with the label computed properties

Ray Wenderlich Functions and Types Course - Part 10

Last chapter! The course suddenly got a lot harder with properties and methods so hopefully this will be accessible. Then it will be the consolidation one! Start Time - 17:47 Inheritance For classes, inheritance is something I've used before. class Person {   var firstName : String   var lastName : String      init (firstName: String , lastName: String ) {     self . firstName = firstName     self . lastName = lastName   } } class Student : Person {   var grades : [ Grade ] = []       } let bob = Student (firstName: "Bob" , lastName: "Stevens" ) All of that is fine. The super and sub class etc. Person is a base class and student inherits from that. Person could have as many sub classes as necessary. You can subclass from a subclass. Paused for approx 25 minutes. Polymorphism - a subclass can be treated as its own type or one of its superclasses. This...

Ray Wenderlich Functions and Types Course - Part 8

Just a little entry to try and maintain some momentum! Going to the next section now. Let's go! Start Time - 20:47 Properties and Methods This is the new chapter! Stored Properties I remember these from before. This is where you have variables/constants within a type and have the values set or they are entered on init. Property Observers Only useful for variable properties. These are only accessible when changing a value but not on init. struct Wizard {          var firstName : String {         willSet {             print ( " \( firstName ) will be set to \(newValue) " )         }         didSet {             if firstName . contains ( " " ) {                 print ( "No spaces! \( firstName ) is not a first name. You need to change to \(oldValue) " )   ...

Stephen DeStefano Swift 5 Course - Part 4 (Lectures 12 to 16)

Image
Not going to go into rambling detail about how it's been a long time etc. End of term, start of holiday is always mental! I have missed my regular coding so am going to get some in today, then there will be more on Monday! I was working through Stephen's course, which was becoming pretty technical and challenging. Let's go! Start Time - 07:17 Stored Properties So these store constant/variable data. A key point here. Structs are value types - if you have a constant stored property, you cannot change the value. You can for classes as they are reference types. All that was pretty easy to be honest. Lazy Properties So I'm just trying to figure out the purpose of these! Stephen is quite rambling. OK so when the property is actually initialised, that's when the lazy stored property is accessed. It's about saving memory. So not created until it has actually been used. If it's computationally expensive - if it will end up slowing things down! Right...

Bob Lee Course Part 15 (Consolidation of Chapter 2 - lectures 16 to 25)

So, a great chance to make sense of all of the concepts in Chapter 2. I will then crack on with Chapter 3 tomorrow! Chapter 2 was all about Object Oriented Swift. A lot of the terminology was familiar but I do feel on the most part (other than singleton stuff...) that my understanding improved with all of this. So let's go over it now! Start Time - 12:03 Convenience Init My Take - this is very simply another way to initialize an object. It's called convenience because the block of code for that init method has it all going on, then the initialisation process is very simple, or convenient. It could be as simple as using () after the class name. Yep, got it! Here's my example from before: class  Human {      var  name:  String      init (name:  String ) {          self . name  = name     }           convenience   init () {     ...

Bob Lee Course Part 12 (consolidation of lectures 17-20)

Before I begin the much-needed consolidation blog, I feel the need to introduce something into my weekly repertoire. Each week, I am going to work on a specific Xcode project! the reason why is that Bob's course is totally separate to the main Xcode project stuff - it's all on playgrounds. That's fine as I am really learning the syntax but I am also losing touch with the practical element of getting code for a potential app together.  So this week I will focus on making a specific project. To start with, it will be a rework of something I have done before with Angela. I'm choosing her because her practical courses have been the most accessible and frankly the best. So after this consolidation entry, I will do an additional one to review what I have done since picking Swift back up in June - some 5 months ago. Also, for this entry, I'm adding in a ' MY TAKE' - so I can make it clearer what I know before revising any content. This is a good way of test...

Bob Lee Course Part 10 (lectures 16 to 18)

Such a busy week - first chance I've had to code for a while! Last time, it was REALLY useful to consolidate and go through what I had done previously. Now I am ready for the next chapter: Object Oriented Programming! Let's go! Start Time - 16:57 Convenience Init I know that these are used with classes but can't remember the purpose of the 'convenience' init. Is this just an alternative way of initializing? Not sure! So this is to do with initializing quickly. Lazy keyword? class Human {     var name: String     init (name: String ) {         self . name = name     } } let larry = Human (name: "Larry" ) let jeff = Human () In the above, an error comes up as I have not initialized the jeff object.  Here we go! class Human {     var name: String     init (name: String ) {         self . name = name     }    ...