developing swift - moving towards the future
TRANSCRIPT
![Page 1: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/1.jpg)
Developing SwiftMoving towards the future
![Page 2: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/2.jpg)
About Inaka• Started in 2010.
• Acquired by Erlang Solutions in 2014.
• We build end-to-end applications with Erlang, Ruby, Web, iOS and Android components.
• We develop highly concurrent application servers such as Whisper and TigerText.
• We're active contributors to the open-source community.
![Page 3: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/3.jpg)
About Me• Pablo Villar.
• iOS Developer.
• Have been working at Inaka for last 2 years.
• Have been working as iOS dev for last 4 years.
• Clean code lover!
![Page 4: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/4.jpg)
What’s Swift?
Why Swift?
How to Swift?
What’s behind Swift?
What’s Swift for?
![Page 5: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/5.jpg)
A little bit of history…
Early 1980's Objective-C
2007 iPhone is born
Late 1980's NeXT license AppKit, FoundationKit
1997 Apple purchases NeXT
2010 iPad is born2015 Watch is born
![Page 6: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/6.jpg)
A little bit of history…
Early 1980's Objective-C
2007 iPhone is born
Late 1980's NeXT license AppKit, FoundationKit
1997 Apple purchases NeXT
2010 iPad is born2015 Watch is born
2014
Swift
![Page 7: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/7.jpg)
2007~2015 (last 8 years)
… ?
IPHONE
IPAD
WATCH
IPOD TOUCH
![Page 8: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/8.jpg)
OBJ-C SWIFT
1980 - Nowadays 2014 - Nowadaysto be deprecated… (?) to keep growing…
![Page 9: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/9.jpg)
A very little bit of history of Swift…
June 2014 Swift 1.0
April 2015 Swift 1.2
October 2015 Swift 2.0
Today
No backwards compatibility
OPEN SOURCE!
![Page 10: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/10.jpg)
BE ADAPTATIVE!
![Page 11: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/11.jpg)
BE PATIENT!
Y U NO WORK?!?!?!
![Page 12: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/12.jpg)
BE TOLERANT!
Y U NO CLEAR?!?!?!
![Page 13: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/13.jpg)
BE ENTHUSIASTIC!
![Page 14: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/14.jpg)
BE ENTHUSIASTIC!
![Page 15: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/15.jpg)
BE ENTHUSIASTIC!
![Page 16: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/16.jpg)
BE CHALLENGED!
Last… Not least.
![Page 17: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/17.jpg)
Now… What you’ve been waiting for…
![Page 18: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/18.jpg)
Now… What you’ve been waiting for…
code!
![Page 19: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/19.jpg)
Now… What you’ve been waiting for…
code!
wasn’t it…?
![Page 20: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/20.jpg)
Now… What you’ve been waiting for…
code!
SAFETY
Optionals
wasn’t it…?
![Page 21: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/21.jpg)
Now… What you’ve been waiting for…
code!
SAFETY
Optionals
String?
Stringnil
wasn’t it…?
![Page 22: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/22.jpg)
Why Optionals?
Things can be nullable
You need a mechanism to properly deal with that
Swift is statically typed
+
![Page 23: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/23.jpg)
Why Optionals?
Things can be nullable
You need a mechanism to properly deal with that
Swift is statically typed
+
String “A regular String, it can’t be nil”
![Page 24: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/24.jpg)
Why Optionals?
Things can be nullable
You need a mechanism to properly deal with that
Swift is statically typed
+
String “A regular String, it can’t be nil”
String? “A String that can be nil”
Optional Type
![Page 25: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/25.jpg)
String? “A String that can be nil”
![Page 26: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/26.jpg)
String? “A String that can be nil”
![Page 27: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/27.jpg)
String? “A
An Optional that can be a String
…or can eventually be nil
String?
Stringnil
![Page 28: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/28.jpg)
String? “A
An Optional that can be a String
…or can eventually be nil
String?
Stringnil Behind the scenes…
enum Optional<T> { case None // nil case Some(T) // a T }
![Page 29: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/29.jpg)
String? “A
An Optional that can be a String
…or can eventually be nil
String?
Stringnil Behind the scenes…
enum Optional<T> { case None // nil case Some(T) // a T }
Optional<String>
![Page 30: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/30.jpg)
Int?
Intnil
A little, yet valuable example…
![Page 31: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/31.jpg)
Int?
Intnil
A little, yet valuable example…
var age: Int?
![Page 32: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/32.jpg)
Int?
Intnil
A little, yet valuable example…
// We prompt the user to enter his/her age.
var age: Int?
![Page 33: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/33.jpg)
Int?
Intnil
A little, yet valuable example…
func greetingForPersonWithAge(age: Int) -> String {
// We prompt the user to enter his/her age.
var age: Int?
switch age { case 0...2: return "Hello baby!" case 3...5: return "How are you doing, toddler?” case 6...12: return "What's up, kid?" case 13...18: return "Yo, what's up?" default: return "Hello, mister!" } }
![Page 34: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/34.jpg)
Int?
Intnil
A little, yet valuable example…
func greetingForPersonWithAge(age: Int) -> String {
// We prompt the user to enter his/her age.
var age: Int?
let greeting = greetingForPersonWithAge(age)
println(greeting)
switch age { case 0...2: return "Hello baby!" case 3...5: return "How are you doing, toddler?” case 6...12: return "What's up, kid?" case 13...18: return "Yo, what's up?" default: return "Hello, mister!" } }
![Page 35: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/35.jpg)
Int?
Intnil
A little, yet valuable example…
func
// We prompt the user to enter his/her age.
var
let greeting = greetingForPersonWithAge(age)
println(
} }
![Page 36: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/36.jpg)
Int?
Intnil
A little, yet valuable example…
func greetingForPersonWithAge(age: Int) -> String {
// We prompt the user to enter his/her age.
var age: Int?
// Int? and Int are not compatible, // You have to deal with it
let greeting = greetingForPersonWithAge(age)
println(greeting)
} }
![Page 37: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/37.jpg)
But, how to…
?
![Page 38: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/38.jpg)
But, how to…
?
var age: Int? = nil
// We prompt the user to enter his/her age.
if let knownAge = age { let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else { println("Hello") // No age. }
![Page 39: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/39.jpg)
But, how to…
?
var age: Int? = nil
// We prompt the user to enter his/her age.
if let knownAge = age { let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else { println("Hello") // No age. }
Init to nil by default
![Page 40: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/40.jpg)
But, how to…
?
var age: Int? = nil
// We prompt the user to enter his/her age.
if let knownAge = age { let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else { println("Hello") // No age. }
Init to nil by default
"Unwrap" the optional
![Page 41: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/41.jpg)
But, how to…
?
var age: Int? = nil
// We prompt the user to enter his/her age.
if let knownAge = age { let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else { println("Hello") // No age. }
Init to nil by default
"Unwrap" the optional
Use the unwrapped one, which is NOT an optional
but an Int
![Page 42: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/42.jpg)
But, how to…
?
var age: Int? = nil
// We prompt the user to enter his/her age.
if let knownAge = age { let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else { println("Hello") // No age. }
Init to nil by default
"Unwrap" the optional
Use the unwrapped one, which is NOT an optional
but an Int
Define a separated behavior to deal with nil values
![Page 43: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/43.jpg)
But, how to…
?
var age: Int? = nil
// We prompt the user to enter his/her age.
if let knownAge = age { let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else { println("Hello") // No age. }
Init to nil by default
"Unwrap" the optional
Use the unwrapped one, which is NOT an optional
but an Int
Define a separated behavior to deal with nil values
SAFETY
![Page 44: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/44.jpg)
A little, yet valuable example…
func greetingForPersonWithAge(age: Int) -> String {
// We prompt the user to enter his/her age.
var age: Int?
if let knownAge = age {
let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else {
println("Hello") // Or show alert. Or whatever.
}
switch age { case 0...2: return "Hello baby!" case 3...5: return "How are you doing, toddler?” case 6...12: return "What's up, kid?" case 13...18: return "Yo, what's up?" default: return "Hello, mister!" } }
(Let’s get ALL the juice from it!)
![Page 45: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/45.jpg)
A little, yet valuable example…
func greetingForPersonWithAge(age: Int) -> String {
// We prompt the user to enter his/her age.
var age: Int?
if let knownAge = age {
let greeting = greetingForPersonWithAge(knownAge) println(greeting) } else {
println("Hello") // Or show alert. Or whatever.
}
} }
(Let’s get ALL the juice from it!)
From this point on, we don’t have to worry about nullability ever again!
![Page 46: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/46.jpg)
In conclusion…
![Page 47: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/47.jpg)
In conclusion…
• Swift changes the way we use to think when it comes to develop mobile apps.
![Page 48: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/48.jpg)
In conclusion…
• Swift changes the way we use to think when it comes to develop mobile apps.
• The language has just been born and it’s growing really fast.
![Page 49: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/49.jpg)
In conclusion…
• Swift changes the way we use to think when it comes to develop mobile apps.
• We’re still in a phase in which there are many bugs and downsides.
• The language has just been born and it’s growing really fast.
![Page 50: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/50.jpg)
In conclusion…
• Swift changes the way we use to think when it comes to develop mobile apps.
• We’re still in a phase in which there are many bugs and downsides.
• The language has just been born and it’s growing really fast.
• But still, promises are big! Swift is the future.
![Page 51: Developing Swift - Moving towards the future](https://reader031.vdocument.in/reader031/viewer/2022022201/589f19421a28ab7b208b4de1/html5/thumbnails/51.jpg)
For more info… Check these out!
https://developer.apple.com/videos/wwdc/2014/
https://developer.apple.com/videos/wwdc/2015/
https://developer.apple.com/swift/resources/
http://www.objc.io/
Cool blogs to learn from…
http://nshipster.com/
Inaka’s webpage:http://inaka.net/
http://inaka.net/blog