Skip to content

Swift 2 notes

Michael Hulse edited this page Feb 14, 2016 · 14 revisions

Notes from Swift: Programming, Master's Handbook.

Atomic Data Types

  1. Booleans: True or False
  2. Integers: Positive and negative whole numbers
  3. Characters: Single ASCII symbol or letter
  4. Floats: Decimal numbers.

Data Sequences & Combinations

  1. Strings: Characters in sequence
  2. Lists: Mutable sequence of individual elements: [3, 1, 4, 9, 2], ["Apple", "Banana", "Caramel"], [true, false, true, true] (values are typically of the same data type)
  3. Enumerations: Immutable sets of data values (values are the same data type)
  4. Itemizations: Combination of different data types to form a finite set: [false, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, true]

Comments

// <- this is a single-line comment
/*
 * <- this is a multi-line comment
 */

Atomic Data

  • Booleans must be lowercase true, false
  • Floats need to have 0 and a decimal place: 0.12 (not .12)

Data Definitions

  • let declares an immutable constant
  • var declares a mutable variable
  • Commas not required at end of lines

Compound/Composite Data

Class and Struct Variables in Swift

… are made up of atomic data and/or other composite structures.

These can be classes or structs.

Think of Classes as Blueprints for a house, and Objects as actual houses designed from the Blueprints.

  • Classes = more flexible
  • Structs = Quicker to load and access

Optional Variables using ?

… are variables that can be defined but do not require an initial value:

let variableName:String?
Clone this wiki locally