O'Reilly logo

Learning iOS 8 Game Development Using Swift by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Classes

Classes are quite easy to create in Swift compared to Objective-C or C++. There is no need for separate files such as an interface file and then an implementation file. Also, there is no property keyword used to define properties. All Swift files end with an extension of .swift.

Properties and initializers

We will have to use the class keyword when creating a class:

Class Character{

var name = "The Dude"

var health = 100

}

Also notice that there is no semicolon after the closing brace. To instantiate a variable of the character type, you can use the following line of code. There is simply no need of alloc as was the case in Objective-C:

var theDude = Character()

The name and health properties can be accessed using the dot operator:

theDude.name ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required