Posts

Showing posts with the label helper methods

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