steam learn: introduction to swift
TRANSCRIPT
3rd of July 2014
SWIFTThe Apple programming language
by Romain Francez
3rd of July 2014
● Apple programming language
● Released during WWDC
● Mac & iOS development
What is SWIFT ?
3rd of July 2014
Anyone can codeSimple
An empty file is a program
A one line file is a programprintln("Hello Steamhouse")
Basic concepts are similar to other languages
Everybody is starting at the same levelBeginner
3rd of July 2014
var aText = "A string" // Type inferenceaText = 1.2 // Cannot convert the expression’s type to String
var numberOverflow: UInt8 = UInt8.max + 1 // Arithmetic operation '255 + 1' (on type 'UInt8') results in an overflow
var tenBillion = 10000000000
var tenBillionReadable = 10_000_000_000
Anyone can codeLess error prone
3rd of July 2014
But can they?Tricky concepts
Optionalsvar anOptional: String?
Inheritanceclass DataViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
Are there a class and two protocols or three protocols?
3rd of July 2014
But can they?Adoption
1,200,000 apps on the iOS App StoreIt will take time to migrate
Sparse documentationOne official document
Unfinished language
No expert on the subject
3rd of July 2014
Language
3rd of July 2014
let greetings = "Hello" // Constant
var person = "World" // Variable
person = "Steamhouse" // Can change the value of a variable
greetings = "Goodbye" // Error, cannot change the value of a constant
BasicsVariables and constants
3rd of July 2014
There is a value… or maybe notvar anOptional: String? = nil // nil means no value
var notAnOptional: String = nil // Error
Accessing the valueif anOptional {
println(anOptional!)
}
BasicsOptionals
3rd of July 2014
func add(a: Int, b: Int) -> Int {
return a + b
}
func adder(a: Int) -> (Int) -> Int {
var _a = a
func add(b: Int) -> Int {
_a += b
return _a
}
return add
}
BasicsFunctions and closures
3rd of July 2014
let (latitude, longitude) = (48.85341, 2.3488)
let paris = (48.85341, 2.3488)
paris.0; paris.1
let parisExplicit = (latitude: 48.85341, longitude: 2.3488)
parisExplicit.latitude; parisExplicit.longitude
BasicsTuples
3rd of July 2014
for i in 0..10 {
i
} // 0 1 2 3 4 5 6 7 8 9
for i in 0...10 {
i
} // 0 1 2 3 4 5 6 7 8 9 10
for _ in 0..10 {
println("Wake up")
}
BasicsFor-In
3rd of July 2014
let point = (+24, -1_302)
switch point {
case (0..5, _):
println("A bit on the right")
case (5..100, _):
println("Somewhat on the right")
case (100...1_000_000, _):
println("On the right")
case (let x, _) where x > 1_000_000:
println("Very far on the right")
default:
break
} // Somewhat on the right
BasicsSwitch
3rd of July 2014
Demo
3rd of July 2014
What the future holds
The APIs are still old styleThey will migrate them in a near future
3rd of July 2014
Questions ?For online questions, please leave a comment on the article.
3rd of July 2014
Join the community !(in Paris)
Social networks :● Follow us on Twitter : https://twitter.com/steamlearn● Like us on Facebook : https://www.facebook.com/steamlearn
SteamLearn is an Inovia initiative : inovia.fr
You wish to be in the audience ? Contact us at [email protected]