8

Advanced Data Types

WHAT'S IN THIS CHAPTER?

  • Modeling data using algebraic data types
  • Improving code quality with optional types
  • Overloading existing operators for new data types
  • Creating custom operators to express the intent of your code
  • Understanding how closures work

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:

  • Casting.playground
  • Closures.playground
  • Custom Operators.playground
  • Dimension.playground
  • JSON.playground
  • Operators.playground
  • Some.playground
  • Tuples.playground

Swift draws inspiration from many languages, especially functional programming languages. While you can certainly get by with the more basic features discussed previously in this book, you will no doubt encounter some of Swift's more advanced features as you become more experienced and proficient in Swift programming. This chapter introduces you to Swift's more advanced concepts, particularly enumerations, optional types, and closures. When you are done, you will have many more tools in your Swift toolbox to help you improve the quality of your code.

WORKING WITH ENUMS AND ALGEBRAIC DATA TYPES

Although Swift is heavily geared toward object-oriented programming, it draws elements and inspiration from many functional programming languages. You've already seen some of these elements, including Swift's use of closures and functions as first-class ...

Get Professional Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.