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

A Swift introduction

Neil Kimmett
February 21, 2017

A Swift introduction

Since its initial release in 2014 and subsequent open-sourcing in 2015 Swift has become one of the most popular programming languages in the world — used everywhere from mobile to Macs to microservices. We will examine the various similarities and differences between Swift and other languages, and take a peek at the unique community that has formed around it.

Neil Kimmett

February 21, 2017
Tweet

More Decks by Neil Kimmett

Other Decks in Technology

Transcript

  1. a Swift
    introduction
    by @neilkimmett

    View Slide

  2. What is ?

    View Slide

  3. View Slide

  4. func move(from start: Point, to end: Point) -> Distance

    View Slide

  5. func move(from start: Point, to end: Point) -> Distance
    player.move(from: here, to: there)

    View Slide

  6. let names: [String] = ["Jeff", "Samantha", "T-Pain"]

    View Slide

  7. let names: [String] = ["Jeff", "Samantha", "T-Pain"]
    names.map({ (string: String) in
    return string.appending(" is super cool!")
    })

    View Slide

  8. let names: [String] = ["Jeff", "Samantha", "T-Pain"]
    names.map({ (string: String) in
    return string.appending(" is super cool!")
    })

    View Slide

  9. let names = ["Jeff", "Samantha", "T-Pain"]
    names.map({ (string: String) in
    return string.appending(" is super cool!")
    })

    View Slide

  10. let names = ["Jeff", "Samantha", "T-Pain"]
    names.map({ (string: String) in
    return string.appending(" is super cool!")
    })

    View Slide

  11. let names = ["Jeff", "Samantha", "T-Pain"]
    names.map({ string in
    return string.appending(" is super cool!")
    })

    View Slide

  12. let names = ["Jeff", "Samantha", "T-Pain"]
    names.map { string in
    return string.appending(" is super cool!")
    }

    View Slide

  13. let names = ["Jeff", "Samantha", "T-Pain"]
    names.map { $0.appending(" is super cool!”) }

    View Slide

  14. class Person {
    }

    View Slide

  15. class Person {
    var name: String
    let dateOfBirth: Date
    }

    View Slide

  16. class Person {
    var name: String
    let dateOfBirth: Date
    init(dateOfBirth: Date, name: String) {
    self.dateOfBirth = dateOfBirth
    self.name = name
    }
    }

    View Slide

  17. class Person {
    var name: String
    let dateOfBirth: Date
    init(dateOfBirth: Date, name: String) {
    self.dateOfBirth = dateOfBirth
    self.name = name
    }
    func dayOfBirth() -> DayOfWeek {
    return …
    }
    }

    View Slide

  18. struct Date {

    }

    View Slide

  19. struct DateFormatter {
    }

    View Slide

  20. struct DateFormatter {
    let format: String
    }

    View Slide

  21. struct DateFormatter {
    let format: String
    func date(from string: String) -> Date
    }

    View Slide

  22. func date(from string: String) -> Date {

    return nil
    }
    ?

    View Slide

  23. let userInput = "1989-08-27"

    View Slide

  24. let userInput = "1989-08-27"
    let formatter = DateFormatter(format: "YYYY-MM-DD")

    View Slide

  25. let userInput = "1989-08-27"
    let formatter = DateFormatter(format: "YYYY-MM-DD")
    let maybeDate = formatter.date(from: userInput)

    View Slide

  26. let userInput = "1989-08-27"
    let formatter = DateFormatter(format: "YYYY-MM-DD")
    let maybeDate = formatter.date(from: userInput)
    if let date = maybeDate {

    }

    View Slide

  27. enum DayOfWeek {
    }

    View Slide

  28. enum DayOfWeek {
    case Mon, Tue, Wed, Thu, Fri, Sat, Sun
    }

    View Slide

  29. enum DayOfWeek {
    case Mon, Tue, Wed, Thu, Fri, Sat, Sun
    func isWeekend() -> Bool {
    switch self {
    case .Mon, .Tue, .Wed, .Thu, .Fri
    return false
    case .Sat, .Sun
    return true
    }
    }

    View Slide

  30. let maybeDate = formatter.date(from: string)
    if let date = maybeDate {
    let person = Person(dateOfBirth: date, name: name)
    if person.dayOfBirth().isWeekend() {

    }
    }

    View Slide

  31. swift.org github.com/apple/swift

    View Slide

  32. github.com/apple/swift-evolution/

    View Slide

  33. Kitura Vapor

    View Slide

  34. Thanks!
    from @neilkimmett
    HARRY’S.com

    View Slide