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

Neil Kimmett

August 22, 2016
Tweet

More Decks by Neil Kimmett

Other Decks in Technology

Transcript

  1. A Swift
    Introduction To
    Swift
    by
    @neilkimmett

    View Slide

  2. Swift is a
    type safe
    language

    View Slide

  3. Types
    Javascript
    "1" + 2 = "12"
    Ruby
    x = 5
    x = "a string"
    x = Dog.new

    View Slide

  4. Types
    Swift
    "1" + 2

    View Slide

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

    View Slide

  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()

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  17. Classes
    class Counter {
    private var count = 0
    func increment() {
    count += 1
    }
    }
    let counter = Counter()
    counter.increment()

    View Slide

  18. Optionals?!

    View Slide

  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 !

    View Slide

  20. ?

    View Slide

  21. Optionals
    class Codebar {
    var location: String? = "Pivotal Labs, EC1V 9NR"
    }
    let codebar = Codebar()
    // stuff
    codebar.location = nil !

    View Slide

  22. Other super awesome stuff
    • structs
    • enums
    • protocols
    • generics
    •  frameworks

    View Slide

  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

    View Slide

  24. Thanks
    ! @neilkimmett
    " [email protected]
    # kimmett.me

    View Slide