O'Reilly logo

Learning Swift™ Programming by Jacob Schatz

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

Properties

This is a good time to talk briefly about getters and setters in Swift. In Swift, you can have a property of a class that is a getter or a setter or both. To see how this works, you’ll create a class called Human, and then you’ll see what it means to get and set properties of that class:

class Human {    var eyeColor = "#00FF00"    var heightInInches = 68    var hairLengthInCM = 2.54    var name = "Skip"}

This class has four properties. You may or may not want all of these properties to be able to be rewritten. For example, once the eye color is set, you might only want that to be able to be read and not written to. There are also other details you can get from these properties being set. For example, ...

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