O'Reilly logo

Professional Swift by Michael Dippery

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

3

Classes, Structs, and Enums

WHAT'S IN THIS CHAPTER?

  • Initializing and deinitializing classes and structs
  • Adding properties to classes and structs
  • Observing changes in property values
  • Understanding methods
  • Defining and using enumerated types

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

You can find the wrox.com downloads for this chapter at http://www.wrox.com/go/proswift on the Download Code tab. The code for this chapter is contained in the following files:

  • AlarmClock.swift
  • BankAccount.swift
  • Playgrounds.zip
  • Square.swift

This chapter covers the object-oriented programming features of the Swift language. Although Swift draws inspiration from a variety of programming languages and programming paradigms, it is, first and foremost, an object-oriented language. Writing programs in Swift requires a thorough understanding of object-oriented programming, and in particular, the object-oriented features available to Swift programmers. After reading this chapter, you should have the knowledge necessary to understand and write code that makes use of Swift's classes, structs, and enumerations.

Many of the examples given in this chapter are found in the Playgrounds.zip file available from the download section of this chapter. Feel free to load those playgrounds into Xcode and experiment on your own as you read the chapter.

WORKING WITH CLASSES AND STRUCTS

Like most object-oriented languages, including Objective-C, Swift supports two basic object-oriented data structures: classes and structs. ...

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