Swiftly Up to Speed

Swiftly Up to Speed

The Power of Swift Types (June 2014)

Swift is a new programming language currently in limited release, but soon millions of Swift programmers will start popping up all around the world.

Want to get ahead of them?

Swift can help you write better programs. Swift can help you create better data structures. Swift can help you think more clearly about unfortunate code corners we all fall into from time to time.

All these new features and capabilities come with a slight learning curve. Even if you write code in a dozen programming languages every day, Swift still has some attention grabbing features.

We're starting out by covering Swift's ability to create custom types.

Swift is an early-binding, strongly-typed language, and Swift takes full advantage of those strong types by letting you create custom types, with full verification at compile time, to improve the reliability and readability of your code.

Chapter Outline

1.  The Power of Swift Types
    1.  Background
    2.  Rationale
    3.  This Book

2.  Introduction to Swift Types
    1.  Let’s Save Half a Billion Dollars
        1.  Addendum

3.  Containers
    1.  struct
        1.  let vs. var
        2.  Type Declarations
        3.  Create an Item
        4.  Update an Item
        5.  Using in Functions
        6.  Functions in Structs
        7.  Revisiting let vs. var

    2.  enum
        1.  Create an Enum
        2.  Enum Default Raw Values
        3.  Creating Enum Value at Runtime
        4.  Reading Enum Values

    3.  class
        1.  Swift Class Basics

    4.  Exercises
        1.  Structs
        2.  Enums
        3.  Classes

    5.  Container Differences
        1.  struct vs. enum
        2.  struct vs. class
        3.  class vs. enum
        4.  Common Among Everything

4.  Real World Example: Stripe Data Types in Swift
    1.  The Stripe API
        1.  The Charge Object
        2.  Modeling the Charge Object
        3.  Modeling IDs
        4.  Refactoring IDs
        5.  Modeling Booleans
        6.  Modeling Money
        7.  Modeling Worldwide Currencies
        8.  Modeling Embedded Objects
        9.  Finally Creating the charge Object
        10. Extra Types
        11. The Remaining 15 Types

5.  JSON From Swift Types
    1.  The Data Model
    2.  The Scaffolding
    3.  The Data Type Implementations
    4.  Creating JSON From Instance Properties

6.  Afterword

Full Chapters

  1. The Power of Swift Types
  2. Introduction to Swift Types
  3. Containers
  4. Real World Example: Stripe Data Types in Swift
  5. JSON From Swift Types