Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Swift Introduction To Swift

A Swift Introduction To Swift

Given at Codebar August 2016 https://codebar.io/meetings/monthly-aug-2016

20cd0627a5c82f8b3e4f30a04745f0cf?s=128

Neil Kimmett

August 22, 2016
Tweet

Transcript

  1. A Swift Introduction To Swift by @neilkimmett

  2. Swift is a type safe language

  3. Types Javascript "1" + 2 = "12" Ruby x =

    5 x = "a string" x = Dog.new
  4. Types Swift "1" + 2

  5. Types Swift var x = 5 x = "a string"

  6. Types let number: Int = 2 let name: String =

    "Sup Codebar" let primes: [Int] = [2, 3, 5, 7, 11] let view: UIView = UIView() view.backgroundColor = UIColor.whiteColor()
  7. ✨ Type inference ✨ let number = 2 let name

    = "Sup Codebar" let primes = [2, 3, 5, 7, 11] let view = UIView() view.backgroundColor = .whiteColor()
  8. Constants & variables let words = "Hello, there" words =

    "Bye for now"
  9. Constants & variables let words = "Hello, there" words =

    "Bye for now"
  10. Constants & variables let words = "Hello, there" words =

    "Bye for now"
  11. Constants & variables var words = "Hello, there" words =

    "Bye for now"
  12. Functions func multiply(array: [Int], by: Int) -> [Int]

  13. Functions func multiply(array: [Int], by: Int) -> [Int] { var

    result = [Int]() for x in array { result.append(x * by) } return result }
  14. Functions func multiply(array: [Int], by: Int) -> [Int] { return

    array.map({ (x) -> Int in return x * by }) }
  15. Functions func multiply(array: [Int], by: Int) -> [Int] { return

    array.map { $0 * by } }
  16. Functions func multiply(array: [Int], by: Int) -> [Int] { return

    array.map { $0 * by } } multiply(array: numbers, by: 2)
  17. Classes class Counter { private var count = 0 func

    increment() { count += 1 } } let counter = Counter() counter.increment()
  18. Optionals?!

  19. Optionals class Codebar { var location: String = "Pivotal Labs,

    EC1V 9NR" } let codebar = Codebar() // insert lots of awesome talks here codebar.location = "The pub" // insert lots of inspiring conversations here codebar.location = nil !
  20. ?

  21. Optionals class Codebar { var location: String? = "Pivotal Labs,

    EC1V 9NR" } let codebar = Codebar() // stuff codebar.location = nil !
  22. Other super awesome stuff • structs • enums • protocols

    • generics •  frameworks
  23. Further reading • "The Swift Programming Language" by Apple •

    raywenderlich.com • swift.org • WWDC videos • IBM Swift Sandbox • Swift Playgrounds for iPad on iOS 10
  24. Thanks ! @neilkimmett " neil@kimmett.me # kimmett.me