$30 off During Our Annual Pro Sale. View Details »

Swift Class & Hackday

Swift Class & Hackday

Some introductory concepts lead to a group building exercise to fix Apple's Swift templates and build a To-Do list app in the process.

Source for the final app can be found here: https://github.com/jpsim/SwiftClassTodo

Source for this talk can be found here: https://github.com/jpsim/talks

JP Simard

July 12, 2014
Tweet

More Decks by JP Simard

Other Decks in Programming

Transcript

  1. SWIFT CLASS + HACKDAY

  2. The set up

  3. THE SETUP Xcode6-Beta3

  4. WHO AM I?

  5. JP SIMARD @SIMJP REALM.IO

  6. TODAY !

  7. CLASS 1. LEARN ABOUT SWIFT 2. BUILD AN APP 3.

    QUESTIONS
  8. WHY SWIFT > OBJC? ▸ Type safety & inference ▸

    Closures ▸ Tuples ▸ Super-Enums ▸ Functional programming ▸ Generics
  9. Q: WHAT DOES IT LOOK LIKE?

  10. TYPE SAFETY & INFERENCE let anInt = 3 let aFloat

    = 0.1416 var pi = anInt + aFloat // Compile warning pi = 3 + 0.1416 // Compiles: number literals are untyped LIKE RUST & SCALA
  11. CLOSURES func backwards(s1: String, s2: String) -> Bool { return

    s1 > s2 } sort(["b", "a"], backwards) // => ["a", "b"] SWIFT CLOSURES ! OBJC BLOCKS
  12. TUPLES let http404Error = (404, "Not Found") LIKE HASKELL &

    SCALA
  13. SUPER-ENUMS* *OK, NOT EXACTLY THE CORRECT TECHNICAL TERM

  14. enum Suit { case Spades, Hearts, Diamonds, Clubs func simpleDescription()

    -> String { switch self { case .Spades: return "Spades" case .Hearts: return "Hearts" case .Diamonds: return "Diamonds" case .Clubs: return "Clubs" } } }
  15. FUNCTIONAL PROGRAMMING let numbers = [1, 5, 3, 12, 2]

    numbers.map { (number: Int) -> Int in return 3 * number } // => [3, 15, 9, 36, 6] numbers.filter {$0 % 2 == 0} // => [12, 2] LIKE HASKELL, SCALA & MANY OTHERS
  16. GENERICS LIKE... UH... EVERY MODERN LANGUAGE!

  17. // Reimplement the Swift standard // library's optional type enum

    OptionalValue<T> { case None case Some(T) } var maybeInt: OptionalValue<Int> = .None maybeInt = .Some(100) // Specialized Array var letters: [Array] letters = ["a"]
  18. Q: WHAT HAPPENED TO MY BELOVED *

  19. Q: WHAT HAPPENED TO MY BELOVED *? ▸ concepts are

    still there: reference types and value types ▸ pointers still exist to interact with C APIs: UnsafePointer<T>, etc.
  20. Q: WHAT HAPPENED TO MY BELOVED *? C APIS ARE

    STILL USABLE import Foundation import Security let secret = "Top Secret".dataUsingEncoding(NSUTF8StringEncoding) let dict = [kSecClass as String: kSecClassGenericPassword, kSecAttrService as String: "MyService", kSecAttrAccount as String: "Some Account", kSecValueData as String: secret] as NSDictionary let status = SecItemAdd(dict as CFDictionaryRef, nil)
  21. JAZZY GITHUB.COM/REALM/JAZZY A SOULFUL WAY TO GENERATE DOCS FOR SWIFT

    & OBJECTIVE-C
  22. LINKS () ▸ Official Swift website ▸ The Swift Programming

    Language Book ▸ WWDC Videos ▸ WWDC Sample Code ▸ Xcode 6 (and other resources) Free Apple Developer Account Required
  23. LINKS (!) ▸ This talk: github.com/jpsim/talks ▸ Jay Freeman's AltConf

    talk: debugging your (Swift) apps with cycript ▸ ObjC/Swift doc generator: github.com/realm/jazzy ▸ Evan Swick: Inside Swift ▸ Swift on StackOverflow
  24. LET'S BUILD A TO-DO APP!

  25. THANK YOU!

  26. Hackday().questions?.askThem!

  27. Hackday().questions?.askThem! JP SIMARD, @SIMJP, REALM.IO