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

A Swift Approach (Warsaw 2014)

Kyle Fuller
November 27, 2014

A Swift Approach (Warsaw 2014)

Kyle Fuller

November 27, 2014
Tweet

More Decks by Kyle Fuller

Other Decks in Technology

Transcript

  1. switch result { case .Error(let error): println("There was an error

    (\(error)).") case .Success(let string): println("\(string)") }
  2. class TestObject { func testA() -> () { println("first test")

    } var testB:(() -> ()) = { println("second test") } }
  3. let string = "Hello World" let matches:[NSTextCheckingResult] = /* regex

    for words in string */ matches.map { string.substringWithRange($0.range) }
  4. let string = "Hello World" let matches:[NSTextCheckingResult] = /* regex

    for words in string */ var strings = [String]() for match in matches { let catch = string.substringWithRange(match.range) strings.append(catch) }
  5. let items = [["a", "b"], ["c", "d"], ["e"]] items.reduce([]) {

    initial, expressions -> [String] in initial + expressions } => ["a", "b", "c", "d", "e"]
  6. let point = (1, 2) switch point { case (0,

    0): println("(0, 0) is at the origin.") case (-2...2, -2...2): println("(\(point.0), \(point.1)) is near the origin.") default: println("The point is at (\(point.0), \(point.1)).") } // prints "(1, 2) is near the origin."
  7. func assert(predicate : () -> Bool) { #if !NDEBUG if

    !predicate() { abort() } #endif }
  8. !