Developing Swift
Moving towards the future
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.
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!
What’s Swift?
Why Swift?
How to Swift?
What’s behind Swift?
What’s Swift for?
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 born
2015 Watch is born
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 born
2015 Watch is born
2014
Swift
2007~2015 (last 8 years)
… ?
IPHONE
IPAD
WATCH
IPOD TOUCH
OBJ-C SWIFT
1980 - Nowadays 2014 - Nowadays
to be deprecated… (?) to keep growing…
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!
BE ADAPTATIVE!
BE PATIENT!
Y U NO WORK?!?!?!
BE TOLERANT!
Y U NO CLEAR?!?!?!
BE ENTHUSIASTIC!
BE ENTHUSIASTIC!
BE ENTHUSIASTIC!
BE CHALLENGED!
Last… Not least.
Now… What you’ve been waiting for…
Now… What you’ve been waiting for…
code!
Now… What you’ve been waiting for…
code!
wasn’t it…?
Now… What you’ve been waiting for…
code!
SAFETY
Optionals
wasn’t it…?
Now… What you’ve been waiting for…
code!
SAFETY
Optionals
String?
String
nil
wasn’t it…?
Why Optionals?
Things can be nullable
You need a mechanism to properly deal with that
Swift is statically typed
+
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”
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
String? “A String that can be nil”
String? “A String that can be nil”
String? “A
An Optional that can be a String
…or can eventually be nil
String?
String
nil
String? “A
An Optional that can be a String
…or can eventually be nil
String?
String
nil Behind the scenes…
enum Optional<T> {
case None // nil
case Some(T) // a T
}
String? “A
An Optional that can be a String
…or can eventually be nil
String?
String
nil Behind the scenes…
enum Optional<T> {
case None // nil
case Some(T) // a T
}
Optional<String>
Int?
Int
nil
A little, yet valuable example…
Int?
Int
nil
A little, yet valuable example…
var age: Int?
Int?
Int
nil
A little, yet valuable example…
// We prompt the user to enter his/her age.
var age: Int?
Int?
Int
nil
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!"
}
}
Int?
Int
nil
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!"
}
}
Int?
Int
nil
A little, yet valuable example…
func
// We prompt the user to enter his/her age.
var
let greeting = greetingForPersonWithAge(age)
println(
}
}
Int?
Int
nil
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)
}
}
But, how to…
?
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.
}
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
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
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
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
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
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!)
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!
In conclusion…
In conclusion…
• Swift changes the way we use to think when it comes to
develop mobile apps.
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.
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.
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.
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

Developing Swift - Moving towards the future

  • 1.
  • 2.
    About Inaka • Startedin 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.
  • 3.
    About Me • PabloVillar. • iOS Developer. • Have been working at Inaka for last 2 years. • Have been working as iOS dev for last 4 years. • Clean code lover!
  • 4.
    What’s Swift? Why Swift? Howto Swift? What’s behind Swift? What’s Swift for?
  • 5.
    A little bitof history… Early 1980's Objective-C 2007 iPhone is born Late 1980's NeXT license AppKit, FoundationKit 1997 Apple purchases NeXT 2010 iPad is born 2015 Watch is born
  • 6.
    A little bitof history… Early 1980's Objective-C 2007 iPhone is born Late 1980's NeXT license AppKit, FoundationKit 1997 Apple purchases NeXT 2010 iPad is born 2015 Watch is born 2014 Swift
  • 7.
    2007~2015 (last 8years) … ? IPHONE IPAD WATCH IPOD TOUCH
  • 8.
    OBJ-C SWIFT 1980 -Nowadays 2014 - Nowadays to be deprecated… (?) to keep growing…
  • 9.
    A very littlebit 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!
  • 10.
  • 11.
    BE PATIENT! Y UNO WORK?!?!?!
  • 12.
    BE TOLERANT! Y UNO CLEAR?!?!?!
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
    Now… What you’vebeen waiting for…
  • 18.
    Now… What you’vebeen waiting for… code!
  • 19.
    Now… What you’vebeen waiting for… code! wasn’t it…?
  • 20.
    Now… What you’vebeen waiting for… code! SAFETY Optionals wasn’t it…?
  • 21.
    Now… What you’vebeen waiting for… code! SAFETY Optionals String? String nil wasn’t it…?
  • 22.
    Why Optionals? Things canbe nullable You need a mechanism to properly deal with that Swift is statically typed +
  • 23.
    Why Optionals? Things canbe nullable You need a mechanism to properly deal with that Swift is statically typed + String “A regular String, it can’t be nil”
  • 24.
    Why Optionals? Things canbe 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
  • 25.
    String? “A Stringthat can be nil”
  • 26.
    String? “A Stringthat can be nil”
  • 27.
    String? “A An Optionalthat can be a String …or can eventually be nil String? String nil
  • 28.
    String? “A An Optionalthat can be a String …or can eventually be nil String? String nil Behind the scenes… enum Optional<T> { case None // nil case Some(T) // a T }
  • 29.
    String? “A An Optionalthat can be a String …or can eventually be nil String? String nil Behind the scenes… enum Optional<T> { case None // nil case Some(T) // a T } Optional<String>
  • 30.
    Int? Int nil A little, yetvaluable example…
  • 31.
    Int? Int nil A little, yetvaluable example… var age: Int?
  • 32.
    Int? Int nil A little, yetvaluable example… // We prompt the user to enter his/her age. var age: Int?
  • 33.
    Int? Int nil A little, yetvaluable 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!" } }
  • 34.
    Int? Int nil A little, yetvaluable 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!" } }
  • 35.
    Int? Int nil A little, yetvaluable example… func // We prompt the user to enter his/her age. var let greeting = greetingForPersonWithAge(age) println( } }
  • 36.
    Int? Int nil A little, yetvaluable 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) } }
  • 37.
  • 38.
    But, how to… ? varage: 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. }
  • 39.
    But, how to… ? varage: 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
  • 40.
    But, how to… ? varage: 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
  • 41.
    But, how to… ? varage: 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
  • 42.
    But, how to… ? varage: 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
  • 43.
    But, how to… ? varage: 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
  • 44.
    A little, yetvaluable 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!)
  • 45.
    A little, yetvaluable 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!
  • 46.
  • 47.
    In conclusion… • Swiftchanges the way we use to think when it comes to develop mobile apps.
  • 48.
    In conclusion… • Swiftchanges 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.
  • 49.
    In conclusion… • Swiftchanges 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.
  • 50.
    In conclusion… • Swiftchanges 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.
  • 51.
    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