0.1 Basics

Naming Style Guide

  • use camel case
  • Class names are capitalized
  • don’t use all caps nor _’s
  • name parameters for functions/inits
  • spaces matter → do not put numbers right next to operation stmts
  • (ie. i>=4 should be i >= 4)

Playground

  • not attached to a file
  • more of a scratch pad for testing
  • cannot be used to test memory management

Scope

  • can access variables only in the portion of the program in which they are declared
  • can be limited to:  if stmts, for loops, functions, classes, global
  • global is the default if declared in an area that isn’t scoped

Data Types

Named

  • type that can be given a particular name when it is defined
  • includes arrays, dictionaries, optionals, classes, structures, enumerations, and protocols

Compound

  • type without a name, defined in the Swift language itself
  • includes tuples, closures, & functions

Declaration

var – used to create a variable
let – used to create a constant

  • use let whenever possible → performance improvements (fixed memory size)
  • when the type is obvious, let Swift infer it
  • types cannot be changed once set