quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

NSScreencast Episode #125 Swift Basics

Swift Basics - NSScreencast

  • swift
  • repl
    • var x = 30
      • no semicolon
    • let y = 50
      • constants
    • var count: Int
      • # count: Int: 0
      • all variable initialized by default value
    • var letter: Character = "A"
      • same as string
  • array
    • var ids: Int[]
      • ids += 1
      • ids += [5,6,7]
      • ids [1,5,6,7]
    • let array => size never change
      • constantsでも中の要素は変わる
      • not immutable
  • range
    • numbers[0..4]
      • not include 1,2,3,4
    • numbers[0...4]
      • include 1,2,3,4,5
    • opposite of Ruby
  • Dictionary
    • separate by colon
    • square bracket
    • var gradebook = [ "Al": "A", "Joe": "B", "Charlie": "D" ]
      • Dictionary<String, String>
    • String?
      • question mark => this value might contain nil
      • force nil check
    • if grade { }
    • grades += grade
      • error: String? not unwrapped
      • unwrapp (!)
        • grades += grade!
    • if let grade =
      • without bang!
  • loop
    • for (student, grade) in gradebook {}
  • string interpolation
    • " (grade)"