O'Reilly logo

Swift Quick Syntax Reference by Matthew Campbell

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

Chapter    36

Class Type Properties

Type properties belong to a particular type, in contrast to the properties discussed in Chapter 34, which belong to instances of a type. You use type properties when you want to have properties that are universal to all instances of that type.

You use the class keyword to declare a type property for a class (see Listing 36-1).

Listing 36-1. Declaring Class Type Properties

class Person {    class var species:String{        return "Homo sapiens"    }    var name: String = "Name"    var age:Int = 0    func profile() -> String {        return "I'm \(self.name) and I'm \(self.age) years old."    }}

In Listing 36-1, you used the class keyword to define the type property species. Type properties for classes must ...

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