Advertisement

To swiftly go where no OS has gone before

Developer Relations Manager
Sep. 23, 2014
Advertisement

More Related Content

Advertisement

To swiftly go where no OS has gone before

  1. Swift & iOS Paul Ardeleanu pa@h24.io @pardel Copyleft 2014 me
  2. CuriosMinds, Brasov, Sept 18th 2014 Slide 2
  3. CuriosMinds, Brasov, Sept 18th 2014 Slide 3
  4. An Android, an iOS, a Blackberry and a Windows Mobile developer walk into a bar… CuriosMinds, Brasov, Sept 18th 2014 Slide 3
  5. An Android, an iOS, a Blackberry and a Windows Mobile developer walk into a bar… The barman looks at them & says… CuriosMinds, Brasov, Sept 18th 2014 Slide 3
  6. An Android, an iOS, a Blackberry and a Windows Mobile developer walk into a bar… The barman looks at them & says… Gee, it must be in town CuriosMinds, Brasov, Sept 18th 2014 Slide 3
  7. Swift & iOS Paul Ardeleanu pa@h24.io @pardel Copyleft 2014 me
  8. To swiftly go where no other language has gone before
  9. Good artists copy, Real artists steal
  10. Everything is a remix https://www.flickr.com/photos/mugley/800999028/
  11. The talk about that new programming language everyone talks about but nobody really uses…
  12. Yet !
  13. Swift & iOS Paul Ardeleanu pa@h24.io @pardel Copyleft 2014 me
  14. Everything is a remix https://www.flickr.com/photos/mugley/800999028/
  15. CuriosMinds, Brasov, Sept 18th 2014 Slide 1 2
  16. CuriosMinds, Brasov, Sept 18th 2014 Slide 1 2
  17. CuriosMinds, Brasov, Sept 18th 2014 Slide 1 3
  18. CuriosMinds, Brasov, Sept 18th 2014 Slide 1 3 #freeJonyIve
  19. CuriosMinds, Brasov, Sept 18th 2014 Slide 1 4
  20. It’s all about the users https://www.flickr.com/photos/wyogirl13/6455191187
  21. It’s all about the users. https://www.flickr.com/photos/wyogirl13/6455191187
  22. It’s all about the users. https://www.flickr.com/photos/wyogirl13/6455191187
  23. Why?
  24. Why? What?
  25. Why? What? When?
  26. Why? What? When? How?
  27. Why?
  28. CuriosMinds, Brasov, Sept 18th 2014 Slide 2 4
  29. CuriosMinds, Brasov, Sept 18th 2014 Slide 2 5 AAPL
  30. CuriosMinds, Brasov, Sept 18th 2014 Slide 2 6 Products
  31. CuriosMinds, Brasov, Sept 18th 2014 Slide 2 7 Software
  32. CuriosMinds, Brasov, Sept 18th 2014 Slide 2 8 App Stores
  33. CuriosMinds, Brasov, Sept 18th 2014 Slide 2 9
  34. Apple needs developers
  35. ‣ maximise the number of developers CuriosMinds, Brasov, Sept 18th 2014 Slide ‣ keeping existing developers happy 31 2 more things…
  36. ‣ 30 year old language ‣ drastically different from other languages ‣ not entirely future-proof CuriosMinds, Brasov, Sept 18th 2014 Slide 32 Objective-C
  37. What?
  38. LLVM & Clang Apps For Good, London, June 29th 2012 Slide 3 4 Hello24 Ltd. (c) 2012
  39. LLVM & Clang gcc => llvm-gcc => llvm Apps For Good, London, June 29th 2012 Slide 3 4 Hello24 Ltd. (c) 2012
  40. Swift
  41. CuriosMinds, Brasov, Sept 18th 2014 Slide Objective-C without the C 36 Swift
  42. CuriosMinds, Brasov, Sept 18th 2014 Slide Objective-C without the C 36 Swift Objective-C is to Swift <=> cat is to cattle
  43. Swift
  44. Safety
  45. Safety - constants vs variables CuriosMinds, Brasov, Sept 18th 2014 Slide 3 9
  46. Safety - constants vs variables CuriosMinds, Brasov, Sept 18th 2014 Slide 3 9 let theAnswer = 42
  47. Safety - constants vs variables CuriosMinds, Brasov, Sept 18th 2014 Slide 3 9 let theAnswer = 42 var numberBooks = 1
  48. Safety - constants vs variables CuriosMinds, Brasov, Sept 18th 2014 Slide 3 9 let theAnswer = 42 var numberBooks = 1 var numberBooks: Int = 1
  49. Safety - no implicit conversion CuriosMinds, Brasov, Sept 18th 2014 Slide 4 0
  50. Safety - no implicit conversion CuriosMinds, Brasov, Sept 18th 2014 Slide 4 0 var numberBooks = 1
  51. Safety - no implicit conversion CuriosMinds, Brasov, Sept 18th 2014 Slide 4 0 var numberBooks = 1 numberBooks = 2.5
  52. Safety - no implicit conversion CuriosMinds, Brasov, Sept 18th 2014 Slide 4 0 var numberBooks = 1 numberBooks = 2.5 ❗️
  53. Safety - no implicit conversion CuriosMinds, Brasov, Sept 18th 2014 Slide 4 0 var numberBooks = 1 numberBooks = 2.5 ❗️ numberBooks = Int(2.5)
  54. Safety - no implicit conversion CuriosMinds, Brasov, Sept 18th 2014 Slide 4 0 var numberBooks = 1 numberBooks = 2.5 ❗️ numberBooks = Int(2.5) ✔
  55. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 1 Safety - switch switch index { case 1: println("first") case 2, 3: println("second or third") case 4...10: println("top 10") default: println("others...") }
  56. New idioms
  57. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 3 Tuples
  58. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 3 Tuples let http404Error = (404, "Not Found")
  59. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 3 Tuples let http404Error = (404, "Not Found") let x = 1 let y = 2 let point = (x, y)
  60. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 3 Tuples let http404Error = (404, "Not Found") let x = 1 let y = 2 let point = (x, y) point.0
  61. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 3 Tuples let http404Error = (404, "Not Found") let x = 1 let y = 2 let point = (x, y) point.0 let origin = (x: 200, y: 100) origin.y
  62. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 4 Tuples
  63. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 4 Tuples // Original var fibonacci = 1 var prev = 0 while fibonacci < 100 { var prev_tmp = fibonacci fibonacci += prev prev = prev_tmp println(fibonacci) }
  64. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 4 Tuples // Original var fibonacci = 1 var prev = 0 while fibonacci < 100 { var prev_tmp = fibonacci fibonacci += prev prev = prev_tmp println(fibonacci) } // tuples var fibonacci_t = 1 var prev_t = 0 while fibonacci_t < 100 { (prev_t, fibonacci_t) = (fibonacci_t, fibonacci_t + prev_t) println(fibonacci_t) }
  65. Functions as 1st class citizens
  66. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 6 Functions func greetingAt(hour: Int) -> (String) -> String { } func morningGreeting(name: String) -> String { return "Good morning (name)" } func afternoonGreeting(name: String) -> String { return "Good afternoon (name)" } return hour < 12 ? morningGreeting : afternoonGreeting
  67. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 6 Functions func greetingAt(hour: Int) -> (String) -> String { } func morningGreeting(name: String) -> String { return "Good morning (name)" } func afternoonGreeting(name: String) -> String { return "Good afternoon (name)" } return hour < 12 ? morningGreeting : afternoonGreeting
  68. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 6 Functions func greetingAt(hour: Int) -> (String) -> String { } func morningGreeting(name: String) -> String { return "Good morning (name)" } func afternoonGreeting(name: String) -> String { return "Good afternoon (name)" } return hour < 12 ? morningGreeting : afternoonGreeting
  69. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 6 Functions func greetingAt(hour: Int) -> (String) -> String { } func morningGreeting(name: String) -> String { return "Good morning (name)" } func afternoonGreeting(name: String) -> String { return "Good afternoon (name)" } return hour < 12 ? morningGreeting : afternoonGreeting
  70. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 6 Functions func greetingAt(hour: Int) -> (String) -> String { } func morningGreeting(name: String) -> String { return "Good morning (name)" } func afternoonGreeting(name: String) -> String { return "Good afternoon (name)" } return hour < 12 ? morningGreeting : afternoonGreeting greetingAt(11)("Paul") greetingAt(14)("Paul")
  71. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 6 Functions func greetingAt(hour: Int) -> (String) -> String { } func morningGreeting(name: String) -> String { return "Good morning (name)" } func afternoonGreeting(name: String) -> String { return "Good afternoon (name)" } return hour < 12 ? morningGreeting : afternoonGreeting greetingAt(11)("Paul") greetingAt(14)("Paul") "Good morning Paul” "Good afternoon Paul"
  72. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 7 Closures
  73. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 7 Closures func greetWithMessage(name: String, message: (String) -> String) -> String { return message(name); }
  74. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 7 Closures func greetWithMessage(name: String, message: (String) -> String) -> String { return message(name); } greetWithMessage("Paul", { (name: String) -> String in return "Good morning (name)" } )
  75. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 7 Closures func greetWithMessage(name: String, message: (String) -> String) -> String { return message(name); } greetWithMessage("Paul", { (name: String) -> String in return "Good morning (name)" } ) greetWithMessage("Paul", { name in return "Good morning (name)" })
  76. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 7 Closures func greetWithMessage(name: String, message: (String) -> String) -> String { return message(name); } greetWithMessage("Paul", { (name: String) -> String in return "Good morning (name)" } ) greetWithMessage("Paul", { name in return "Good morning (name)" }) greetWithMessage("Paul") { name in return "Good morning (name)" }
  77. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 7 Closures func greetWithMessage(name: String, message: (String) -> String) -> String { return message(name); } greetWithMessage("Paul", { (name: String) -> String in return "Good morning (name)" } ) greetWithMessage("Paul", { name in return "Good morning (name)" }) greetWithMessage("Paul") { name in return "Good morning (name)" } greetWithMessage("Paul") { return "Good morning ($0)" }
  78. CuriosMinds, Brasov, Sept 18th 2014 Slide 4 8
  79. Tools
  80. Playgrounds
  81. Module 01 Slide 5 2 Hello24 Ltd. (c) 2014 New Playground
  82. Module 01 Slide 5 3 Hello24 Ltd. (c) 2014 Empty Playground
  83. Module 01 Slide 5 4 Hello24 Ltd. (c) 2014 Playground
  84. Module 01 Slide 5 5 Hello24 Ltd. (c) 2014 Playground
  85. Module 01 Slide 5 5 Hello24 Ltd. (c) 2014 Playground
  86. Module 01 Slide 5 5 Hello24 Ltd. (c) 2014 Playground
  87. Module 01 Slide 5 6 Hello24 Ltd. (c) 2014 Fibonacci
  88. Module 01 Slide 5 7 Hello24 Ltd. (c) 2014 Fibonacci
  89. Module 01 Slide 5 8 Hello24 Ltd. (c) 2014 Fibonacci
  90. Module 01 Slide 5 9 Hello24 Ltd. (c) 2014 Playground - Timeline
  91. Module 01 Slide 6 0 Hello24 Ltd. (c) 2014 Playgrounds
  92. Module 01 Slide Hello24 Ltd. (c) 2014 ‣ Interactive experience ‣ Immediate feedback ‣ Watch code progression through loops 60 Playgrounds
  93. Module 01 Slide Hello24 Ltd. (c) 2014 ‣ Interactive experience ‣ Immediate feedback ‣ Watch code progression through loops ‣ Easy way to ‣ prototype ‣ test snippets of code 60 Playgrounds
  94. Module 01 Slide Hello24 Ltd. (c) 2014 ‣ Interactive experience ‣ Immediate feedback ‣ Watch code progression through loops ‣ Easy way to ‣ prototype ‣ test snippets of code ‣ CAREFUL! Executed automatically. 60 Playgrounds
  95. Swift REPL
  96. Module 01 Slide 6 2 Hello24 Ltd. (c) 2014 REPL Read–eval–print loop
  97. Module 01 Slide 6 2 Hello24 Ltd. (c) 2014 REPL Read–eval–print loop $ which swift /usr/bin/swift
  98. Module 01 Slide 6 2 Hello24 Ltd. (c) 2014 REPL Read–eval–print loop $ which swift /usr/bin/swift $ swift -v Swift version 1.0 (swift-600.0.51.3) Target: x86_64-apple-darwin14.0.0 <unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift
  99. Module 01 Slide 6 3 Hello24 Ltd. (c) 2014 man swift
  100. Module 01 Slide 6 4 Hello24 Ltd. (c) 2014 REPL
  101. REPL $ swift -v … <unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift Module 01 Slide 6 4 Hello24 Ltd. (c) 2014
  102. REPL $ swift -v … <unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift Module 01 Slide 6 4 Hello24 Ltd. (c) 2014
  103. REPL $ swift -v … <unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift Module 01 Slide 6 4 Hello24 Ltd. (c) 2014
  104. Module 01 Slide 6 5 Hello24 Ltd. (c) 2014 REPL
  105. Module 01 Slide 6 5 Hello24 Ltd. (c) 2014 REPL $ swift -v
  106. Module 01 Slide 6 5 Hello24 Ltd. (c) 2014 REPL $ swift -v Swift version 1.1 (swift-600.0.54.4) Target: x86_64-apple-darwin14.0.0 /Applications/Xcode-Beta.app/Contents/Developer/usr/bin/lldb "--repl=-target x86_64-apple-darwin14.0.0 -target-cpu core2 -sdk /Applications/Xcode- Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ MacOSX10.10.sdk -color-diagnostics"
  107. Module 01 Slide 6 5 Hello24 Ltd. (c) 2014 REPL $ swift -v Swift version 1.1 (swift-600.0.54.4) Target: x86_64-apple-darwin14.0.0 /Applications/Xcode-Beta.app/Contents/Developer/usr/bin/lldb "--repl=-target x86_64-apple-darwin14.0.0 -target-cpu core2 -sdk /Applications/Xcode- Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ MacOSX10.10.sdk -color-diagnostics" $ swift Welcome to Swift! Type :help for assistance.
  108. Module 01 Slide 6 6 Hello24 Ltd. (c) 2014 REPL $ swift Welcome to Swift! Type :help for assistance. 1> 1 + 2 $R0: Int = 3 2> "once upon a time" $R1: String = "once upon a time" 3> $R1 + " there were ($R0) bears" $R2: String = "once upon a time there were 3 bears" 4> println($R2) once upon a time there were 3 bears
  109. When?
  110. ‣ iOS 8 released yesterday ‣ Swift is v.1.0 as of Sept 9th ‣ Xcode 6.0.1 released yesterday ‣ Apps written in Swift started being accepted on Sept 9th CuriosMinds, Brasov, Sept 18th 2014 Slide 68 Now!
  111. CuriosMinds, Brasov, Sept 18th 2014 Slide 6 9 Resources
  112. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 0 Resources
  113. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 1 My Book pa@h24.io
  114. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 2
  115. How?
  116. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 4 Swift project
  117. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 5 Bridging
  118. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 6 Bridging
  119. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 7 // // STDataObject.swift // import Foundation import CoreData class STDataObject: NSManagedObject { @NSManaged var uuid: String? @NSManaged var sync_uuid: String? @NSManaged var is_active: NSNumber class func managedObjectContext() -> NSManagedObjectContext? { var appDelegate = UIApplication.sharedApplication().delegate as AppDelegate return appDelegate.managedObjectContext } … }
  120. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 8
  121. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 8
  122. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 9
  123. CuriosMinds, Brasov, Sept 18th 2014 Slide 7 9
  124. Objective-C ➾ Swift
  125. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 1 Fizz Buzz classic
  126. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 1 Fizz Buzz classic let fizzBuzz = ({ (n: Int) -> String in if( 0 == (n % 3 + n % 5)) { return "FizzBuzz" } if( 0 == n % 3) { return "Fizz" } if( 0 == n % 5) { return "Buzz" } else { return "(n)" } }) fizzBuzz(1) fizzBuzz(2) fizzBuzz(3) fizzBuzz(5) fizzBuzz(9) fizzBuzz(10) fizzBuzz(15)
  127. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 1 Fizz Buzz classic let fizzBuzz = ({ (n: Int) -> String in if( 0 == (n % 3 + n % 5)) { return "FizzBuzz" } if( 0 == n % 3) { return "Fizz" } if( 0 == n % 5) { return "Buzz" } else { return "(n)" } }) fizzBuzz(1) fizzBuzz(2) fizzBuzz(3) fizzBuzz(5) fizzBuzz(9) fizzBuzz(10) fizzBuzz(15) “1” “2” “fizz” “buzz” “fizz” “buzz” “fizzbuzz”
  128. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 2 Swift Fizz Buzz
  129. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 2 Swift Fizz Buzz let swiftFizzBuzz = ({ (aNumber: Int) -> String in switch (aNumber % 3, aNumber % 5 ) { case (0, 0): return "FizzBuzz" case (0, _): return "Fizz" case (_, 0): return "Buzz" default: return "(aNumber)" } }) swiftFizzBuzz(1) swiftFizzBuzz(2) swiftFizzBuzz(3) swiftFizzBuzz(5) swiftFizzBuzz(9) swiftFizzBuzz(10) swiftFizzBuzz(15)
  130. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 2 Swift Fizz Buzz let swiftFizzBuzz = ({ (aNumber: Int) -> String in switch (aNumber % 3, aNumber % 5 ) { case (0, 0): return "FizzBuzz" case (0, _): return "Fizz" case (_, 0): return "Buzz" default: return "(aNumber)" } }) swiftFizzBuzz(1) swiftFizzBuzz(2) swiftFizzBuzz(3) swiftFizzBuzz(5) swiftFizzBuzz(9) swiftFizzBuzz(10) swiftFizzBuzz(15) “1” “2” “fizz” “buzz” “fizz” “buzz” “fizzbuzz”
  131. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 3 Fizz Buzz - side by side let fizzBuzz = ({ (n: Int) -> String in if( 0 == (n % 3 + n % 5)) { return "FizzBuzz" } if( 0 == n % 3) { return "Fizz" } if( 0 == n % 5) { return "Buzz" } else { return "(n)" } }) let swiftFizzBuzz = ({ (aNumber: Int) -> String in switch (aNumber % 3, aNumber % 5 ) { case (0, 0): return "FizzBuzz" case (0, _): return "Fizz" case (_, 0): return "Buzz" default: return "(aNumber)" } })
  132. Objective-C ➾ Swift
  133. CuriosMinds, Brasov, Sept 18th 2014 Slide 8 5
  134. Thank you! Paul Ardeleanu pa@h24.io @pardel Copyleft 2014 me
Advertisement