steam learn: introduction to swift

17
3rd of July 2014 SWIFT The Apple programming language by Romain Francez

Upload: inovia

Post on 14-Aug-2015

31 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Steam Learn: Introduction to SWIFT

3rd of July 2014

SWIFTThe Apple programming language

by Romain Francez

Page 2: Steam Learn: Introduction to SWIFT

3rd of July 2014

● Apple programming language

● Released during WWDC

● Mac & iOS development

What is SWIFT ?

Page 3: Steam Learn: Introduction to 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

Page 4: Steam Learn: Introduction to SWIFT

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

Page 5: Steam Learn: Introduction to SWIFT

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?

Page 6: Steam Learn: Introduction to SWIFT

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

Page 7: Steam Learn: Introduction to SWIFT

3rd of July 2014

Language

Page 8: Steam Learn: Introduction to SWIFT

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

Page 9: Steam Learn: Introduction to SWIFT

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

Page 10: Steam Learn: Introduction to SWIFT

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

Page 11: Steam Learn: Introduction to SWIFT

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

Page 12: Steam Learn: Introduction to SWIFT

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

Page 13: Steam Learn: Introduction to SWIFT

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

Page 14: Steam Learn: Introduction to SWIFT

3rd of July 2014

Demo

Page 15: Steam Learn: Introduction to SWIFT

3rd of July 2014

What the future holds

The APIs are still old styleThey will migrate them in a near future

Page 16: Steam Learn: Introduction to SWIFT

3rd of July 2014

Questions ?For online questions, please leave a comment on the article.

Page 17: Steam Learn: Introduction to SWIFT

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]