Posts

Showing posts with the label references

Classes and Structs - interim Practice!

So I was all ready to move onto the next course but really feel the need to crack the whole initialiser (which is one of the most difficult words to type by the way!) thing first. It makes more sense to have a little more practice with this! So for the first time since going back to Treehouse, I'm veering away from it - albeit briefly... First stop - the Apple Developer Guidance Structures  and  classes  are general-purpose, flexible constructs that become the building blocks of your program’s code. You define properties and methods to add functionality to your structures and classes using the same syntax you use to define constants, variables, and functions. Straight from the text! All of that makes sense. Pasan also referred to them as 'Objects'. Ah hang on, that's an instance of a construct. Again, from the text, here is what both Structures and Classes can do: Define properties to store values Define methods to provide functionality Define subscripts t...

Object Oriented Swift: Class Inheritance; Differentiating between Objects

Some of the content in the previous videos was confusing to say the least! I've looked over the 'Helper Method' part again and was actually going to do a separate blog. However, halfway through that I realised I just can't make sense of so many previous values and properties being used. It did seem to be a giant conceptual leap! Anyway, I can always look back over that again, when I get to a similar level of difficulty at some point. The main point of the 'Helper Methods' was that a function is created specifically to help with another one within a class/struct.  Inheritance So far in the game we have, we haven't accounted for enemies getting harder. A stronger enemy needs to be created! Now, I remember the point of this - that a class will inherit the properties of another one. Structs cannot do this! Pasan shows that you can just create new classes, copy and paste the code then tweak the value of the life property. However, DRY - don't repeat yours...