Posts

Enumerations and Optionals: Intro to Enumerations (Part 2)

Continuing with Enums...really enjoying these so far! Associated Enums Pasan mentioned a 'wrapper' object...apparently we will find out more! In the example of a colour component enum, we need to provide associated enums...Adding in four float values in brackets - these four represent the rgb colour case. enum ColourCoomponent {     case rgb ( Float , Float , Float , Float )     case hsb      } The same needs to be done for the  hsb case. So for each Enum member, there are parameters involved. Accessing them with the dot notation means they are properties? enum ColourCoomponent {     case rgb ( Float , Float , Float , Float )     case hsb ( Float , Float , Float , Float )      } let colour = ColourCoomponent . hsb ( 55 , 77 , 91 , 109 ) Methods on Enumerations A point Pasan makes straight away is that an enum is not really an object - we don't create insta...

Enumerations and Optionals: Intro to Enums (Part 1)

So here we go! I'm now 'up to date'. I can't claim that I've gone over EVERYTHING that I had learned in the previous few years, but by going through the four Treehouse courses, I feel as though I have a thorough understanding of what I should know. Just to recap, I've been re-learning constants, variables, types, operations, collections, conditionals and control flow, functions, methods, classes and structures...that's actually really impressive! I got a little lost towards the end of classes - specifically the initialisation aspect, plus the fact that I was combining a lot of concepts together. I tried to go over this but it is genuinely a real challenge to make sense of; the key point is that I've tried and will continue to gain experience. Yesterday, I looked up the init aspect and tried out a few more examples, plus went over with my 'Swifty' app. It's coming!  Now, moving onwards, I'm doing a course about enumerations. From what I ...

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

Object-Oriented Swift - Classes

Yep, two in a day - I couldn't resist! A great sign that I want to work through more coding! I'm picking back up with where I got to - from structures to classes... Introduction to Classes The syntax for these is similar in terms of the UpperCamelCase etc. A variable is used as a property rather than a constant because this value is likely to change. One of the differences with structs and classes are that we almost must write the init methods in the latter. Initializer methods are always just init, no need for prepositional phrases etc. class Enemy {          var life: Int = 2     let position: Point          init (x: Int , y: Int ) {         self . position = Point (x: x, y: y)              }          func decreaseLife(by factor: Int ) {                  life -= f...