SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
SWIFT INTRODUCTION 
by Giuseppe Arici & Matteo Battaglio 
@ Codemotion Milan, 29/11/2014, v 1.1-S
A SWIFT INTRODUCTION 
TO THE NEW APPLE PROGRAMMING LANGUAGE
HELLO WORLD 
▸ Giuseppe Arici & Matteo Battaglio 
▸ iOS devs @ Tiltap / Superpartes 
▸ #pragma mark co-founders 
▸ Codemotion friends 
▸  addicted
[This] Short Presentation @ SlideShare 
http://slideshare.net/giuseppearici/swift-introduction 
Long Presentation @ SlideShare 
http://slideshare.net/giuseppearici/swift-programminglanguage 
Sample Code @ GitHub 
https://github.com/madbat/swift-fun-playgrounds
HISTORY
LANGUAGE FATHER 
Chris Lattner
LANGUAGE BIRTH 
I started work on the Swift Programming Language in July of 2010. I 
implemented much of the basic language structure, with only a few 
people knowing of its existence. A few other (amazing) people started 
contributing in earnest late in 2011, and it became a major focus for the 
Apple Developer Tools group in July 2013. 
— Chris Lattner
LANGUAGE INSPIRATION 
The Swift Programming Language greatly benefited from the 
experiences hard-won by many other languages in the field, drawing 
ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too 
many others to list. 
— Chris Lattner
PRINCIPLES
SWIFT PROGRAMMING LANGUAGE 
imperative, functional, object oriented, multi-paradigm, 
static, strong typed, type safe, inferred, 
general purpose, compiled, fast, 
modern, elegant, clean, 
funny, happy, 
❤️
SYNTAX
Immutable & Mutable 
Functions & Closures 
Tuples & Pattern Matching 
Data Types & Instances 
Protocols & Extensions 
Generics & Optionals
IMMUTABLE & MUTABLE
CONSTANTS & VARIABLES 
TYPE ANNOTATIONS & TYPE INFERENCE 
let constant: Int = 1 // Type Annotations 
let constant = 1 // Type Inference (as Int) 
let constant = 1 // readonly, cannot be re-assigned 
constant = 2 // ❌ ERROR !!! 
var variable = 1 // readwrite, can be re-assigned 
variable = 2 // OK 
By convention you should prefer to use 'let' over 'var'
CONSTANTS & VARIABLES 
UNICODE CHARACTERS IN CONSTANT & VARIABLE NAMES 
let !!!! = 4 
var """"" = 5 
! KILLER APPLICATION "
VALUE & REFERENCE TYPES 
ENUMERATIONS & STRUCTURES VS CLASSES 
▸ Enumerations & Structures are passed by Value 
▸ Classes are passed by Reference 
ENUMERATIONS & STRUCTURES ARE ALWAYS COPIED WHEN THEY ARE PASSED AROUND IN THE 
CODE, AND DO NOT USE REFERENCE COUNTING.
STRUCTURES 
MANY SWIFT LIBRARY'S BASE TYPES ARE STRUCTURES 
// String 
let string = "Codemotion" 
// Character 
let character: Character = "c" 
// Array 
let array = ["A", "B"] 
// Dictionary 
let dictionary = ["First" : 1, "Second" : 2]
STRUCTURES 
CONSTANT & VARIABLE ARRAYS 
let constantArray = ["A"] 
var variableArray = ["A"] 
constantArray = ["X"] // ❌ ERROR !!! 
constantArray[0] = "Y" // ❌ ERROR !!! 
constantArray.append("B"); // ❌ ERROR !!! 
constantArray.removeAtIndex(0) // ❌ ERROR !!! 
variableArray = ["X"] // ["X"] 
variableArray[0] = "A" // ["A"] 
variableArray.append("B"); // ["A", "B"] 
variableArray.removeAtIndex(0) // ["B"]
FUNCTIONS & CLOSURES
FUNCTIONS 
FIRST-CLASS FUNCTION 
▸ assign a function to variable 
▸ pass function as argument to another function 
▸ return a function from a function 
▸ functional programming patterns: map, filter, ...
FUNCTIONS 
DECLARATION & CALL 
// declaration 
func foo(parameter1: Type1, parameter1: Type2) -> ReturnType { 
/* function body */ 
} 
// call 
foo(argument1, argument2) 
// external and local parameter names 
func bar(externalParameterName localParameterName: Type) { 
/* body use localParameterName */ 
} 
// call must use externalParameterName label 
bar(externalParameterName: argument)
CLOSURES 
MEANING & SYNTAX 
// Closures are blocks of functionality that can be passed around 
{ (parameter1: Type1, parameter2: Type2) -> ReturnType in 
/ * ... */ 
} 
// Closures can capture and store references to any constants and 
// variables from the context in which they are defined.
FUNCTIONS VS CLOSURES 
▸ Global functions: 
NAMED CLOSURES / DO NOT CAPTURE ANY VALUES 
▸ Nested functions: 
NAMED CLOSURES / CAPTURE VALUES FROM ENCLOSING FUNCTION 
▸ Closure expressions: 
UNNAMED CLOSURES / CAPTURE VALUES FROM THEIR CONTEXT
FUNCTIONS VS CLOSURES 
SORTING WITHOUT CLOSURES 
// define a function which takes an array and a sorting algorithm 
func sorted(array: [Int], algorithm: (Int, Int) -> Bool) -> [Int] { 
/* apply the sorting algorithm to the array */ 
} 
// define an array 
let array = [1, 2, 3] 
// define a sorting algorithm funtion 
func backwards(i1: Int, i2: Int) { 
return i1 > i2 
} 
// call sorted 
var reversed = sorted(array, backwards)
FUNCTIONS VS CLOSURES 
SORTING WITH CLOSURES 1/2 
// Fully declared closure 
reversed = sorted(array, { (i1: Int, i2: Int) -> Bool in return i1 > i2 } ) 
// Infer closure type 
reversed = sorted(array, { (i1, i2) in return i1 > i2 } ) 
// Implicit returns 
reversed = sorted(array, { (i1, i2) in i1 > i2 } )
FUNCTIONS VS CLOSURES 
SORTING WITH CLOSURES 2/2 
// Shorthand argument names 
reversed = sorted(array, { $0 > $1 } ) 
// Trailing closure: outside of () only if it's function’s final argument 
reversed = sorted(array) { $0 > $1 } 
// Operator functions 
reversed = sorted(array, >)
TUPLES & PATTERN MATCHING
TUPLES 
LIGHTWEIGHT CONTAINERS FOR MULTIPLE VALUES 
let complex = (1.0, -2.0) // Compound Type: (Double, Double) 
let (real, imag) = complex // Decompose 
let (real, _) = complex // Underscores ignore value 
// Access by index 
let real = complex.0 
let imag = complex.1 
// Name elements 
let complex = (real: 1.0, imag: -2.0) 
let real = complex.real
PATTERN MATCHING 
let point = (42, 42) 
switch point { // break by default 
case (0, 0): 
println("match a specific tuple") 
case (_, 0): 
println("ignore undescore value") 
case (let x, 1): 
println("bind a value to x") 
case let (x, y) where x == y: 
println("bind values which satify the where clause") 
default: 
println("must be exhaustive") 
}
DATA TYPES & INSTANCES
ENUMERATIONS, STRUCTURES & CLASSES 
COMMON CAPABILITIES 
▸ Stored & Computed Properties 
▸ Methods, Subscripts & Initializers 
▸ Protocols & Extensions 
▸ Access Control
ENUMERATIONS, STRUCTURES & CLASSES 
public class Vehicle { 
// stored instance property 
private let name: String 
// computed instance property 
public var formattedName: String { return "vehicle: (name)" } 
// type property 
class var maxSpeed : Int { return 299_792_458 } 
// initializer 
init (name: String) { self.name = name } 
// instance method 
internal func move() { /* ... */ } 
}
CLASSES Only 
ADDITIONAL CAPABILITIES: 
▸ Inheritance 
▸ Type casting 
▸ Deinitializers 
▸ Reference counting
CLASSES Only 
public class Car: Vehicle { // inheritance 
// override 
public override var formattedName: String { return "car: (name)" } 
// designated initializer 
override init(name: String) { super.init(name: name);} 
// convenience initializer 
convenience init() { self.init(name: "Car") } 
// deinitializer 
deinit { /* clean up */ } 
} 
let vehicle = Car(name: "Supercar") 
let car = vehicle as Car // Type Casting
PROTOCOLS & EXTENSIONS
PROTOCOLS 
// Available for Enumerations, Structures & Classes 
protocol SomeProtocol { // define a set of requirements 
var instanceProperty: Type { get set } // require instance properties 
class var typeProperty: Type { get set } // require type properties 
func someMethod() // require instance methods 
class func someTypeMethod() // require type methods 
init() // require initializers 
}
EXTENSIONS 
// Available for Enumerations, Structures & Classes 
extension SomeType: SomeProtocol { // add protocol conformance 
var stored = 1 // ❌ ERROR !!! // CANNOT add store properties ! 
var computed: String { /* ... */ } // add computed properties 
func method() { /* ... */ } // add methods 
subscript(i: Int) -> String { /* ... */ } // add subscripts 
init(parameter: Type) { /* ... */ } // add initializers 
enum SomeEnum { /* ... */ } // add nested types 
}
EXTENSIONS 
EXTENSIONS CAN EXTEND ALSO SWIFT LIBRARY TYPES 
extension Int { 
func times(task: () -> ()) { 
for i in 0 ..< self { 
task() 
} 
} 
} 
3.times({ println("Developer! ") }) 
// Developer! Developer! Developer! !
GENERICS & OPTIONALS
GENERICS 
// Specific Functions 
func swapTwoStrings(inout a: String, inout b: String) { 
let temporaryA = a; a = b; b = temporaryA 
} 
func swapTwoDoubles(inout a: Double, inout b: Double) { 
let temporaryA = a; a = b; b = temporaryA 
} 
// Generic Function 
func swapTwoValues<T>(inout a: T, inout b: T) { 
let temporaryA = a; a = b; b = temporaryA 
} 
var someInt = 1, anotherInt = 2 
swapTwoValues(&someInt, &anotherInt) // T == Int 
// someInt == 2, anotherInt == 1
GENERICS 
WHERE CLAUSES ON TYPE CONSTRAINTS 
protocol Container { typealias ItemType } 
func allItemsMatch< 
C1: Container, C2: Container 
where C1.ItemType == C2.ItemType, C1.ItemType: Equatable> 
(container1: C1, container2: C2) -> Bool { 
if container1.count != container2.count { return false } 
for i in 0..<container1.count { 
if container1[i] != container2[i] { 
return false 
} 
} 
return true // all items match 
} 
}
OPTIONALS 
AN OPTIONAL VALUE EITHER CONTAINS A VALUE OR NIL 
var optionalInt: Int? = 42 
optionalInt = nil // to indicate that the value is missing 
var optionalDouble: Double? // automatically sets to nil 
// Check if nil 
optionalDouble == nil 
optionalDouble != nil
OPTIONALS 
// Force unwrap 
let optionalInt: Int? = 42 
let definitelyInt = optionalInt! // throws runtime error if nil 
// Optional binding 
if let definitelyInt = optionalInt { 
// runs if optionalInt is not nil and sets definitelyInt: Int 
} 
// Implicitly Unwrapped Optionals 
var assumedInt: Int! // set to nil 
assumedInt = 42 
var implicitInt: Int = assumedInt // do not need an exclamation mark 
assumedInt = nil 
implicitInt = assumedInt // ❌ RUNTIME ERROR !!!
OPTIONALS 
class Car { 
var model: String 
init(model: String) { self.model = model } 
func jump() -> String? { 
if model == "Supercar" { return "!⚡️" } 
else { return nil } } 
} 
// Return type of chaining is always optional 
var car1: Car? = nil; car1?.model // nil: String? 
var car2: Car? = Car(model: "Supercar"); car2?.model // "Supercar": String? 
// Chain on optional return value 
car1?.jump()?.hasPrefix("!") // type Bool?
OPTIONALS 
A GENERIC ENUMERATION WITH ASSOCIATED VALUE 
enum Optional<T> : Reflectable, NilLiteralConvertible { 
case None 
case Some(T) 
/* ... */ 
} 
var maybeInt1: Int? = nil 
var maybeInt2: Optional<Int> = .None 
maybeInt1 = 42 
maybeInt2 = .Some(42)
TOOLS & 
PRACTICE
LET'S PLAY WITH SWIFT 
▸ Swift in playground 
▸ Swift distinctive features 
! 
LET'S SEE IT IN ACTION!
FINAL THOUGHTS
SWIFT VS ... ? 
▸ Swift vs Scala 
▸ Swift vs Rust 
▸ Swift vs C# 
Swift is Objective-C without the C
OPEN SOURCE SWIFT ? 
Guys, feel free to make up your own dragons if you want, but your 
speculation is just that: speculation. We literally have not even 
discussed this yet, because we have a ton of work to do [...] You can 
imagine that many of us want it to be open source and part of llvm, but 
the discussion hasn't happened yet, and won't for some time. 
— Chris Lattner @ llvmdev
WHAT SWIFT IS MISSING ? 
[ SWIFT 1.1 IN XCODE 6.1 ] 
▸ Compiler attributes and Preprocessor 
▸ Class Variables, Exceptions, KVO, KVC and Reflection6 
HTTPS://GITHUB.COM/KSM/SWIFTINFLUX 
6 Though it’s not documented in the Swift Standard Library — and is subject to change — Swift has a reflection API: 
let mirror = reflect(instance) // see Reflectable Protocol
SWIFT IN PRODUCTION ? 
▸ Companies are doing it 
▸ Freelances are doing it 
▸ Many of us are doing it 
▸ But be careful if you do it ! 
A few apps that were built using Swift @ apple.com
Q&A
THANKS see you @ https://fb.com/groups/pragmamark 
@giuseppearici / giuseppe.arici@pragmamark.org 
@m4dbat / matteo.battaglio@pragmamark.org

Contenu connexe

Tendances

A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 
Swift Programming
Swift ProgrammingSwift Programming
Swift ProgrammingCodemotion
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageSmartLogic
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app developmentopenak
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascriptReece Carlson
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHPWim Godden
 
FParsec Hands On - F#unctional Londoners 2014
FParsec Hands On -  F#unctional Londoners 2014FParsec Hands On -  F#unctional Londoners 2014
FParsec Hands On - F#unctional Londoners 2014Phillip Trelford
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScriptSimon Willison
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayAlexis Gallagher
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic courseTran Khoa
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsRasan Samarasinghe
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic JavascriptBunlong Van
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014hwilming
 

Tendances (20)

A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Swift Programming
Swift ProgrammingSwift Programming
Swift Programming
 
Introduction to Swift
Introduction to SwiftIntroduction to Swift
Introduction to Swift
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app development
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
FParsec Hands On - F#unctional Londoners 2014
FParsec Hands On -  F#unctional Londoners 2014FParsec Hands On -  F#unctional Londoners 2014
FParsec Hands On - F#unctional Londoners 2014
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
Kotlin
KotlinKotlin
Kotlin
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
SWIFT 3
SWIFT 3SWIFT 3
SWIFT 3
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic Javascript
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
 

En vedette

Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...
Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...
Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...needlesselectio95
 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightGiuseppe Arici
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference CountingGiuseppe Arici
 
Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013Giuseppe Arici
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - CJussi Pohjolainen
 
Securing the Cloud
Securing the CloudSecuring the Cloud
Securing the CloudGGV Capital
 
Creative Traction Methodology - For Early Stage Startups
Creative Traction Methodology - For Early Stage StartupsCreative Traction Methodology - For Early Stage Startups
Creative Traction Methodology - For Early Stage StartupsTommaso Di Bartolo
 
IT in Healthcare
IT in HealthcareIT in Healthcare
IT in HealthcareNetApp
 
[Infographic] How will Internet of Things (IoT) change the world as we know it?
[Infographic] How will Internet of Things (IoT) change the world as we know it?[Infographic] How will Internet of Things (IoT) change the world as we know it?
[Infographic] How will Internet of Things (IoT) change the world as we know it?InterQuest Group
 
Network Effects
Network EffectsNetwork Effects
Network Effectsa16z
 
Mobile Is Eating the World (2016)
Mobile Is Eating the World (2016)Mobile Is Eating the World (2016)
Mobile Is Eating the World (2016)a16z
 

En vedette (17)

Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...
Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...
Mozilla’s Webmaker app will make it easy for anyone to create Web apps on the...
 
Digital Universitas
Digital UniversitasDigital Universitas
Digital Universitas
 
GDB Mobile
GDB MobileGDB Mobile
GDB Mobile
 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma Night
 
Objective-C @ ITIS
Objective-C @ ITISObjective-C @ ITIS
Objective-C @ ITIS
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference Counting
 
Parte II Objective C
Parte II   Objective CParte II   Objective C
Parte II Objective C
 
Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013
 
Objective-C
Objective-CObjective-C
Objective-C
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
Securing the Cloud
Securing the CloudSecuring the Cloud
Securing the Cloud
 
Creative Traction Methodology - For Early Stage Startups
Creative Traction Methodology - For Early Stage StartupsCreative Traction Methodology - For Early Stage Startups
Creative Traction Methodology - For Early Stage Startups
 
IT in Healthcare
IT in HealthcareIT in Healthcare
IT in Healthcare
 
[Infographic] How will Internet of Things (IoT) change the world as we know it?
[Infographic] How will Internet of Things (IoT) change the world as we know it?[Infographic] How will Internet of Things (IoT) change the world as we know it?
[Infographic] How will Internet of Things (IoT) change the world as we know it?
 
Network Effects
Network EffectsNetwork Effects
Network Effects
 
Mobile Is Eating the World (2016)
Mobile Is Eating the World (2016)Mobile Is Eating the World (2016)
Mobile Is Eating the World (2016)
 

Similaire à Swift Introduction

golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdfSpam92
 
Objective-C to Swift - Swift Cloud Workshop 3
Objective-C to Swift - Swift Cloud Workshop 3Objective-C to Swift - Swift Cloud Workshop 3
Objective-C to Swift - Swift Cloud Workshop 3Randy Scovil
 
F# and Reactive Programming for iOS
F# and Reactive Programming for iOSF# and Reactive Programming for iOS
F# and Reactive Programming for iOSBrad Pillow
 
Commenting in Agile Development
Commenting in Agile DevelopmentCommenting in Agile Development
Commenting in Agile DevelopmentJan Rybák Benetka
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an OverviewRoberto Casadei
 
Oop lect3.pptx
Oop lect3.pptxOop lect3.pptx
Oop lect3.pptxMrMudassir
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... FunctionsMichal Bigos
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScriptAleš Najmann
 
What is storage class
What is storage classWhat is storage class
What is storage classIsha Aggarwal
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.Russell Childs
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to DartRamesh Nair
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 

Similaire à Swift Introduction (20)

Workshop Swift
Workshop Swift Workshop Swift
Workshop Swift
 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdf
 
Objective-C to Swift - Swift Cloud Workshop 3
Objective-C to Swift - Swift Cloud Workshop 3Objective-C to Swift - Swift Cloud Workshop 3
Objective-C to Swift - Swift Cloud Workshop 3
 
F# and Reactive Programming for iOS
F# and Reactive Programming for iOSF# and Reactive Programming for iOS
F# and Reactive Programming for iOS
 
Introduction to Swift 2
Introduction to Swift 2Introduction to Swift 2
Introduction to Swift 2
 
Commenting in Agile Development
Commenting in Agile DevelopmentCommenting in Agile Development
Commenting in Agile Development
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an Overview
 
Oop lect3.pptx
Oop lect3.pptxOop lect3.pptx
Oop lect3.pptx
 
Csharp4 generics
Csharp4 genericsCsharp4 generics
Csharp4 generics
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... Functions
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
VHDL lecture 2.ppt
VHDL lecture 2.pptVHDL lecture 2.ppt
VHDL lecture 2.ppt
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Generics_RIO.ppt
Generics_RIO.pptGenerics_RIO.ppt
Generics_RIO.ppt
 

Dernier

Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Dernier (20)

Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 

Swift Introduction

  • 1. SWIFT INTRODUCTION by Giuseppe Arici & Matteo Battaglio @ Codemotion Milan, 29/11/2014, v 1.1-S
  • 2. A SWIFT INTRODUCTION TO THE NEW APPLE PROGRAMMING LANGUAGE
  • 3. HELLO WORLD ▸ Giuseppe Arici & Matteo Battaglio ▸ iOS devs @ Tiltap / Superpartes ▸ #pragma mark co-founders ▸ Codemotion friends ▸  addicted
  • 4. [This] Short Presentation @ SlideShare http://slideshare.net/giuseppearici/swift-introduction Long Presentation @ SlideShare http://slideshare.net/giuseppearici/swift-programminglanguage Sample Code @ GitHub https://github.com/madbat/swift-fun-playgrounds
  • 7. LANGUAGE BIRTH I started work on the Swift Programming Language in July of 2010. I implemented much of the basic language structure, with only a few people knowing of its existence. A few other (amazing) people started contributing in earnest late in 2011, and it became a major focus for the Apple Developer Tools group in July 2013. — Chris Lattner
  • 8. LANGUAGE INSPIRATION The Swift Programming Language greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list. — Chris Lattner
  • 10. SWIFT PROGRAMMING LANGUAGE imperative, functional, object oriented, multi-paradigm, static, strong typed, type safe, inferred, general purpose, compiled, fast, modern, elegant, clean, funny, happy, ❤️
  • 12. Immutable & Mutable Functions & Closures Tuples & Pattern Matching Data Types & Instances Protocols & Extensions Generics & Optionals
  • 14. CONSTANTS & VARIABLES TYPE ANNOTATIONS & TYPE INFERENCE let constant: Int = 1 // Type Annotations let constant = 1 // Type Inference (as Int) let constant = 1 // readonly, cannot be re-assigned constant = 2 // ❌ ERROR !!! var variable = 1 // readwrite, can be re-assigned variable = 2 // OK By convention you should prefer to use 'let' over 'var'
  • 15. CONSTANTS & VARIABLES UNICODE CHARACTERS IN CONSTANT & VARIABLE NAMES let !!!! = 4 var """"" = 5 ! KILLER APPLICATION "
  • 16. VALUE & REFERENCE TYPES ENUMERATIONS & STRUCTURES VS CLASSES ▸ Enumerations & Structures are passed by Value ▸ Classes are passed by Reference ENUMERATIONS & STRUCTURES ARE ALWAYS COPIED WHEN THEY ARE PASSED AROUND IN THE CODE, AND DO NOT USE REFERENCE COUNTING.
  • 17. STRUCTURES MANY SWIFT LIBRARY'S BASE TYPES ARE STRUCTURES // String let string = "Codemotion" // Character let character: Character = "c" // Array let array = ["A", "B"] // Dictionary let dictionary = ["First" : 1, "Second" : 2]
  • 18. STRUCTURES CONSTANT & VARIABLE ARRAYS let constantArray = ["A"] var variableArray = ["A"] constantArray = ["X"] // ❌ ERROR !!! constantArray[0] = "Y" // ❌ ERROR !!! constantArray.append("B"); // ❌ ERROR !!! constantArray.removeAtIndex(0) // ❌ ERROR !!! variableArray = ["X"] // ["X"] variableArray[0] = "A" // ["A"] variableArray.append("B"); // ["A", "B"] variableArray.removeAtIndex(0) // ["B"]
  • 20. FUNCTIONS FIRST-CLASS FUNCTION ▸ assign a function to variable ▸ pass function as argument to another function ▸ return a function from a function ▸ functional programming patterns: map, filter, ...
  • 21. FUNCTIONS DECLARATION & CALL // declaration func foo(parameter1: Type1, parameter1: Type2) -> ReturnType { /* function body */ } // call foo(argument1, argument2) // external and local parameter names func bar(externalParameterName localParameterName: Type) { /* body use localParameterName */ } // call must use externalParameterName label bar(externalParameterName: argument)
  • 22. CLOSURES MEANING & SYNTAX // Closures are blocks of functionality that can be passed around { (parameter1: Type1, parameter2: Type2) -> ReturnType in / * ... */ } // Closures can capture and store references to any constants and // variables from the context in which they are defined.
  • 23. FUNCTIONS VS CLOSURES ▸ Global functions: NAMED CLOSURES / DO NOT CAPTURE ANY VALUES ▸ Nested functions: NAMED CLOSURES / CAPTURE VALUES FROM ENCLOSING FUNCTION ▸ Closure expressions: UNNAMED CLOSURES / CAPTURE VALUES FROM THEIR CONTEXT
  • 24. FUNCTIONS VS CLOSURES SORTING WITHOUT CLOSURES // define a function which takes an array and a sorting algorithm func sorted(array: [Int], algorithm: (Int, Int) -> Bool) -> [Int] { /* apply the sorting algorithm to the array */ } // define an array let array = [1, 2, 3] // define a sorting algorithm funtion func backwards(i1: Int, i2: Int) { return i1 > i2 } // call sorted var reversed = sorted(array, backwards)
  • 25. FUNCTIONS VS CLOSURES SORTING WITH CLOSURES 1/2 // Fully declared closure reversed = sorted(array, { (i1: Int, i2: Int) -> Bool in return i1 > i2 } ) // Infer closure type reversed = sorted(array, { (i1, i2) in return i1 > i2 } ) // Implicit returns reversed = sorted(array, { (i1, i2) in i1 > i2 } )
  • 26. FUNCTIONS VS CLOSURES SORTING WITH CLOSURES 2/2 // Shorthand argument names reversed = sorted(array, { $0 > $1 } ) // Trailing closure: outside of () only if it's function’s final argument reversed = sorted(array) { $0 > $1 } // Operator functions reversed = sorted(array, >)
  • 27. TUPLES & PATTERN MATCHING
  • 28. TUPLES LIGHTWEIGHT CONTAINERS FOR MULTIPLE VALUES let complex = (1.0, -2.0) // Compound Type: (Double, Double) let (real, imag) = complex // Decompose let (real, _) = complex // Underscores ignore value // Access by index let real = complex.0 let imag = complex.1 // Name elements let complex = (real: 1.0, imag: -2.0) let real = complex.real
  • 29. PATTERN MATCHING let point = (42, 42) switch point { // break by default case (0, 0): println("match a specific tuple") case (_, 0): println("ignore undescore value") case (let x, 1): println("bind a value to x") case let (x, y) where x == y: println("bind values which satify the where clause") default: println("must be exhaustive") }
  • 30. DATA TYPES & INSTANCES
  • 31. ENUMERATIONS, STRUCTURES & CLASSES COMMON CAPABILITIES ▸ Stored & Computed Properties ▸ Methods, Subscripts & Initializers ▸ Protocols & Extensions ▸ Access Control
  • 32. ENUMERATIONS, STRUCTURES & CLASSES public class Vehicle { // stored instance property private let name: String // computed instance property public var formattedName: String { return "vehicle: (name)" } // type property class var maxSpeed : Int { return 299_792_458 } // initializer init (name: String) { self.name = name } // instance method internal func move() { /* ... */ } }
  • 33. CLASSES Only ADDITIONAL CAPABILITIES: ▸ Inheritance ▸ Type casting ▸ Deinitializers ▸ Reference counting
  • 34. CLASSES Only public class Car: Vehicle { // inheritance // override public override var formattedName: String { return "car: (name)" } // designated initializer override init(name: String) { super.init(name: name);} // convenience initializer convenience init() { self.init(name: "Car") } // deinitializer deinit { /* clean up */ } } let vehicle = Car(name: "Supercar") let car = vehicle as Car // Type Casting
  • 36. PROTOCOLS // Available for Enumerations, Structures & Classes protocol SomeProtocol { // define a set of requirements var instanceProperty: Type { get set } // require instance properties class var typeProperty: Type { get set } // require type properties func someMethod() // require instance methods class func someTypeMethod() // require type methods init() // require initializers }
  • 37. EXTENSIONS // Available for Enumerations, Structures & Classes extension SomeType: SomeProtocol { // add protocol conformance var stored = 1 // ❌ ERROR !!! // CANNOT add store properties ! var computed: String { /* ... */ } // add computed properties func method() { /* ... */ } // add methods subscript(i: Int) -> String { /* ... */ } // add subscripts init(parameter: Type) { /* ... */ } // add initializers enum SomeEnum { /* ... */ } // add nested types }
  • 38. EXTENSIONS EXTENSIONS CAN EXTEND ALSO SWIFT LIBRARY TYPES extension Int { func times(task: () -> ()) { for i in 0 ..< self { task() } } } 3.times({ println("Developer! ") }) // Developer! Developer! Developer! !
  • 40. GENERICS // Specific Functions func swapTwoStrings(inout a: String, inout b: String) { let temporaryA = a; a = b; b = temporaryA } func swapTwoDoubles(inout a: Double, inout b: Double) { let temporaryA = a; a = b; b = temporaryA } // Generic Function func swapTwoValues<T>(inout a: T, inout b: T) { let temporaryA = a; a = b; b = temporaryA } var someInt = 1, anotherInt = 2 swapTwoValues(&someInt, &anotherInt) // T == Int // someInt == 2, anotherInt == 1
  • 41. GENERICS WHERE CLAUSES ON TYPE CONSTRAINTS protocol Container { typealias ItemType } func allItemsMatch< C1: Container, C2: Container where C1.ItemType == C2.ItemType, C1.ItemType: Equatable> (container1: C1, container2: C2) -> Bool { if container1.count != container2.count { return false } for i in 0..<container1.count { if container1[i] != container2[i] { return false } } return true // all items match } }
  • 42. OPTIONALS AN OPTIONAL VALUE EITHER CONTAINS A VALUE OR NIL var optionalInt: Int? = 42 optionalInt = nil // to indicate that the value is missing var optionalDouble: Double? // automatically sets to nil // Check if nil optionalDouble == nil optionalDouble != nil
  • 43. OPTIONALS // Force unwrap let optionalInt: Int? = 42 let definitelyInt = optionalInt! // throws runtime error if nil // Optional binding if let definitelyInt = optionalInt { // runs if optionalInt is not nil and sets definitelyInt: Int } // Implicitly Unwrapped Optionals var assumedInt: Int! // set to nil assumedInt = 42 var implicitInt: Int = assumedInt // do not need an exclamation mark assumedInt = nil implicitInt = assumedInt // ❌ RUNTIME ERROR !!!
  • 44. OPTIONALS class Car { var model: String init(model: String) { self.model = model } func jump() -> String? { if model == "Supercar" { return "!⚡️" } else { return nil } } } // Return type of chaining is always optional var car1: Car? = nil; car1?.model // nil: String? var car2: Car? = Car(model: "Supercar"); car2?.model // "Supercar": String? // Chain on optional return value car1?.jump()?.hasPrefix("!") // type Bool?
  • 45. OPTIONALS A GENERIC ENUMERATION WITH ASSOCIATED VALUE enum Optional<T> : Reflectable, NilLiteralConvertible { case None case Some(T) /* ... */ } var maybeInt1: Int? = nil var maybeInt2: Optional<Int> = .None maybeInt1 = 42 maybeInt2 = .Some(42)
  • 47. LET'S PLAY WITH SWIFT ▸ Swift in playground ▸ Swift distinctive features ! LET'S SEE IT IN ACTION!
  • 49. SWIFT VS ... ? ▸ Swift vs Scala ▸ Swift vs Rust ▸ Swift vs C# Swift is Objective-C without the C
  • 50. OPEN SOURCE SWIFT ? Guys, feel free to make up your own dragons if you want, but your speculation is just that: speculation. We literally have not even discussed this yet, because we have a ton of work to do [...] You can imagine that many of us want it to be open source and part of llvm, but the discussion hasn't happened yet, and won't for some time. — Chris Lattner @ llvmdev
  • 51. WHAT SWIFT IS MISSING ? [ SWIFT 1.1 IN XCODE 6.1 ] ▸ Compiler attributes and Preprocessor ▸ Class Variables, Exceptions, KVO, KVC and Reflection6 HTTPS://GITHUB.COM/KSM/SWIFTINFLUX 6 Though it’s not documented in the Swift Standard Library — and is subject to change — Swift has a reflection API: let mirror = reflect(instance) // see Reflectable Protocol
  • 52. SWIFT IN PRODUCTION ? ▸ Companies are doing it ▸ Freelances are doing it ▸ Many of us are doing it ▸ But be careful if you do it ! A few apps that were built using Swift @ apple.com
  • 53. Q&A
  • 54. THANKS see you @ https://fb.com/groups/pragmamark @giuseppearici / giuseppe.arici@pragmamark.org @m4dbat / matteo.battaglio@pragmamark.org