Reading 1 : Swift Reading

Table Of Contents

Swift Programming Language

Read the sections described below in the The Swift Programming Language: Language Guide. The goal of this reading is not to learn every aspect of Swift, but rather to learn the basics, become familiar with the documentation and where to find details of specific features, and to see lots of examples. To better emphasize important concepts, the sections in the reading have been annotated with three colors:

  • Very Important : Read these carefully. They may more subtle than other parts but are important.
  • Important : Read these carefully as well, but they should be easier to understand.
  • Optional : Not required for now.

The Basics

  • Constants and Variables Comments
  • Semicolons
  • Integers
  • Floating-Point Numbers
  • Type Safety and Type Inference
  • Numeric Literals
  • Numeric Type Conversion
  • Type Aliases
  • Booleans
  • Tuples
  • Optionals
  • Error Handling
  • Assertions and Preconditions

Basic Operators

  • Terminology
  • Assignment Operator
  • Arithmetic Operators
  • Compound Assignment Operators
  • Comparison Operators
  • Ternary Conditional Operator
  • Nil-Coalescing Operator
  • Range Operators
  • Logical Operators

Strings and Characters

  • String Literals
  • Initializing an Empty String
  • String Mutability
  • Strings Are Value Types
  • Working with Characters
  • Concatenating Strings and Characters
  • String Interpolation
  • Unicode
  • Counting Characters
  • Accessing and Modifying a String
  • Substrings
  • Comparing Strings
  • Unicode Representations of Strings

Collection Types

  • Mutability of Collections
  • Arrays
  • Sets
  • Performing Set Operations
  • Dictionaries

Control Flow

  • For-In Loops
  • While Loops
  • Conditional Statements
    • If
    • Switch
    • No Implicit Fallthrough
    • Interval Matching
    • Tuples
    • Value Bindings
    • Where
    • Compound Cases
  • Control Transfer Statements
    • Continue
    • Break
    • Fallthrough
    • Labeled Statements
  • Early Exit
  • Checking API Availability

Functions

  • Functions
  • Defining and Calling Functions
  • Function Parameters and Return Values
    • Functions Without Parameters
    • Functions With Multiple Parameters
    • Functions Without Return Values
    • Functions With Multiple Return Values
  • Function Argument Labels and Parameter Names
    • Specifying Argument Labels
    • Omitting Argument Labels
    • Default Parameter Values
    • Variadic Parameters
    • In-Out Parameters
  • Function Types
  • Nested Functions

Closures

Enumerations

  • Enumeration Syntax
  • Matching Enumeration Values with a Switch Statement
  • Associated Values
  • Raw Values
  • Recursive Enumerations

Classes and Structures

  • Comparing Classes and Structures
  • Structures and Enumerations Are Value Types (ignore enumerations)
  • Classes Are Reference Types
  • Choosing Between Classes and Structures
  • Assignment and Copy Behavior for Strings, Arrays and Dictionaries

Properties

  • Stored Properties
  • Computed Properties
  • Property Observers
  • Global and Local Variables
  • Type Properties

Methods

  • Instance Methods
    • The self Property
    • Modifying Value Types from Within Instance Methods
    • Assigning to self Within a Mutating Method
  • Type Methods

Subscripts

Inheritance

  • Defining a Base Class
  • Subclassing
  • Overriding
    • Accessing Superclass Methods, Properties, and Subscripts
    • Overriding Methods
    • Overriding Properties
  • Preventing Overrides

Initialization

  • Setting Initial Values for Stored Properties
  • Customizing Initialization
  • Default Initializers
  • Class Inheritance and Initialization
  • Failable Initializers
  • Required Initializers
  • Setting a Default Property Value with a Closure or Function

Swift API Guidelines

Read the Swift API Design Guidelines. Some of what is in this document will be a bit hard to fully absorb until you have more experience using Swift, but familiarizing yourself with what is in this document is crucial to writing good Swift code. The goal is to know what’s there rather than fully master the guidelines. You should refer back to this document often. A few details:

  • Be sure to click everywhere that it says “MORE DETAIL”.
  • Pay special attention to the “Write a documentation comment” section.
  • Pay special attention to the “Follow case conventions” section.
  • Pay special attention to the entire “Argument Labels” section.
  • You can ignore (for now), points that reference Protocols. When we learn about Protocols next week, be sure to check back with this document after that.
  • You can also ignore the final section (Special Instructions) for now.