Date post: | 11-Feb-2017 |
Category: |
Software |
Upload: | pablo-villar |
View: | 169 times |
Download: | 2 times |
Developing SwiftMoving 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 born2015 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 born2015 Watch is born
2014
Swift
2007~2015 (last 8 years)
… ?
IPHONE
IPAD
WATCH
IPOD TOUCH
OBJ-C SWIFT
1980 - Nowadays 2014 - Nowadaysto 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?
Stringnil
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?
Stringnil
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 }
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>
Int?
Intnil
A little, yet valuable example…
Int?
Intnil
A little, yet valuable example…
var age: Int?
Int?
Intnil
A little, yet valuable example…
// We prompt the user to enter his/her age.
var age: Int?
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!" } }
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!" } }
Int?
Intnil
A little, yet valuable example…
func
// We prompt the user to enter his/her age.
var
let greeting = greetingForPersonWithAge(age)
println(
} }
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)
} }
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