SlideShare a Scribd company logo
1 of 97
Download to read offline
10 reasons you'll love Swift 
Paul Ardeleanu 
© 2014 Hello24 Ltd. 
hello24.com
here
TIOBE Index for Nov 2014 
Slide 5 Hello24 Ltd. (c) 2014
TIOBE Index for Nov 2014 
Slide 6 Hello24 Ltd. (c) 2014
Why a new language?
Slide 8 Hello24 Ltd. (c) 2014 
AAPL
Slide 9 Hello24 Ltd. (c) 2014 
Products
Slide 1 0 Hello24 Ltd. (c) 2014 
Software
Slide 1 1 Hello24 Ltd. (c) 2014 
App Stores
Slide 1 2 Hello24 Ltd. (c) 2014 
Apps
Apple needs developers
Slide Hello24 Ltd. (c) 2014 
‣ maximise the number of developers 
‣ keeping existing developers happy 
14 
2 ways…
Slide Hello24 Ltd. (c) 2014 
‣ 30 year old language 
‣ drastically different from other languages 
‣ not entirely future-proof 
15 
Objective-C
How did this happen?
LLVM & Clang 
gcc => llvm-gcc => llvm
Swift 
Objective-C without C 
Slide Hello24 Ltd. (c) 2014 
19 
Objective-C is to Swift == cat is to cattle
10 reasons you'll love Swift
1. No C
Slide 2 2 Hello24 Ltd. (c) 2014 
No main( ) function
Slide 2 3 Hello24 Ltd. (c) 2014 
No [, ] or ;
2. Modern
Module 02 Slide Hello24 Ltd. (c) 2014 
let http404Error = (404, "Not Found") 
25 
Tuples 
let x = 1 
let y = 2 
let point = (x, y) (.0 1, .1 2) 
point.0 1 
let origin = (x: 200, y: 100) 
origin.y 
(.0 200, .1 100) 
100
Module 02 Slide Hello24 Ltd. (c) 2014 
// Original 
var fibonacci = 1 
var prev = 0 
while fibonacci < 100 { 
var prev_tmp = fibonacci 
fibonacci += prev 
prev = prev_tmp 
println(fibonacci) 
} 
26 
Fibonacci Tuples 
// tuples 
var fibonacci = 1 
var prev = 0 
while fibonacci < 100 { 
(prev, fibonacci) = (fibonacci, fibonacci + prev) 
println(fibonacci) 
}
Nil coalescing operator 
var b = a ?? "default value" 
Module 02 Slide 2 7 Hello24 Ltd. (c) 2014
3. Safety
Slide Hello24 Ltd. (c) 2014 
let theAnswer = 42 
29 
Constants & variables 
var numberBooks = 1 
var numberBooks: Int = 1
Safety - no implicit conversion 
Slide 3 0 Hello24 Ltd. (c) 2014 
let theAnswer2 = 42 
let trueAnswer = Double(theAnswer) + 0.0001 
let aNumber:UInt8 = 42 
let anotherNumber:Int64 = Int64(aNumber)
Slide 3 1 Hello24 Ltd. (c) 2014 
Safety - switch 
switch (aNumber % 3, aNumber % 5 ) { 
case (0, 0): 
println("fizzbuzz") 
case (0, _): 
println("fizz") 
case (_, 0): 
println("buzz") 
default: 
println(aNumber) 
}
Module 06 Slide 3 2 Hello24 Ltd. (c) 2014 
Classes vs. Structures 
struct Point { 
var x = 0 
var y = 0 
static var counter = 0 
static let origin = Point() 
var description: String { 
get { 
switch (point.x, point.y) { 
case (let 0, 0): 
return "origin" 
case (let x, 0): 
return "on the y axis - x = (case (0, let y): 
return "on the x axis - y = (default: 
return "(point.x)x(point.y)" 
} 
} 
} 
func distanceToOrigin() -> Double { 
return … 
} 
} 
class Fruit { 
var color: String 
var diameter: Int 
var area: Double { 
get { 
return self.width * self.height 
} 
set(newValue) { 
self.width = sqrt(newValue) 
self.height = sqrt(newValue) 
} 
} 
init(color: String, diameter: Int) { 
self.color = color 
self.diameter = diameter 
} 
func area() -> Double { 
return self.width * self.height 
} 
}
Module 06 Slide 3 3 Hello24 Ltd. (c) 2014 
Classes vs. Structures 
Classes Structs 
passed by reference value 
inheritance ✔ ✘ 
initializers must be defined auto-generated 
member-wise initialiser 
deinitializer ✔ ✘ 
introspection ✔ ✘ 
ideal for complex data relatively simple data *
Module 05 Slide 3 4 Hello24 Ltd. (c) 2014 
Value type (Structures) 
var point1 = Point(x: 100, y: 200) 
var point2 = point1 
x: 100 
point1.x = 120 
point1 y : 200 
x: 100 
point2 y : 200
Module 05 Slide 3 5 Hello24 Ltd. (c) 2014 
Value type (Structures) 
var point1 = Point(x: 100, y: 200) 
var point2 = point1 
x: 120 
point1.x = 120 
point1 y : 200 
x: 100 
point2 y : 200
Module 06 Slide 3 6 Hello24 Ltd. (c) 2014 
Reference type (Classes) 
var rectangle1 = Rect() 
rectangle1.width = 100 
var rectangle2 = rectangle1 
rectangle2.width = 200 
width: 100 
rectangle1 height: 0 
rectangle2
Module 06 Slide 3 7 Hello24 Ltd. (c) 2014 
Reference type (Classes) 
var rectangle1 = Rect() 
rectangle1.width = 100 
var rectangle2 = rectangle1 
rectangle2.width = 200 
width: 200 
rectangle1 height: 0 
rectangle2
nil
4. Optionals
❗️ 
Module 02 Slide 4 1 Hello24 Ltd. (c) 2014 
Optionals 
var answer: Int = 42 
var theAnswer: Int = nil 
var theAnswer: Int? ✔ 
theAnswer = 42 
nil 
{Some 42}
Optionals == Schrödinger’s cat 
Can either: 
‣ be nil 
‣ contain a value 
Module 02 Slide 4 2 Hello24 Ltd. (c) 2014
Module 02 Slide 4 3 Hello24 Ltd. (c) 2014 
Using an optional 
var theAnswer: Int? 
if theAnswer != nil { 
var x = 4 + theAnswer 
} 
❗️
Module 02 Slide 4 4 Hello24 Ltd. (c) 2014 
Forced Unwrapping 
var theAnswer: Int? 
if theAnswer != nil { 
var x = 4 + theAnswer! 
} 
✔
Module 02 Slide 4 5 Hello24 Ltd. (c) 2014 
Optional binding 
if theAnswer != nil { 
if let answer = theAnswer { 
var x = 4 + answer 
} 
var x = 4 + theAnswer! 
} 
no !
Module 02 Slide 4 6 Hello24 Ltd. (c) 2014 
Optionals 
var theAnswer: Int? 
if theAnswer != nil { 
var x = 4 + theAnswer! 
} 
theAnswer!
Module 02 Slide 4 7 Hello24 Ltd. (c) 2014 
Optionals 
var theAnswer = 42 
var theAnswer: Int? 
var theAnswer: Int! 
- always has a value 
- type can be inferred 
- either nil or has a value 
- must be unwrapped 
- nil until first assignment 
- assumed to always have a value
Nil coalescing operator 
Module 02 Slide 4 8 Hello24 Ltd. (c) 2014 
var theAnswer: Int? 
var x = theAnswer ?? 12 
equivalent to: 
var x = (theAnswer != nil) ? theAnswer! : 12
5. Mix & match
Slide 5 0 Hello24 Ltd. (c) 2014 
Swift project
Slide 5 1 Hello24 Ltd. (c) 2014 
Bridging
Slide 5 2 Hello24 Ltd. (c) 2014 
Bridging
Slide 5 3 Hello24 Ltd. (c) 2014 
Bridging 
class STDataObject: NSManagedObject { 
@NSManaged var uuid: String? 
@NSManaged var sync_uuid: String? 
@NSManaged var is_active: NSNumber 
class func managedObjectContext() -> NSManagedObjectContext? { 
var appDelegate = UIApplication.sharedApplication().delegate 
as AppDelegate 
return appDelegate.managedObjectContext 
}
6. Functions as 
first class citizens
Module 04 Slide 5 5 Hello24 Ltd. (c) 2014 
Function structure 
function 
name 
parameter 
name 
parameter 
type 
func greet(title: String, person: String) -> String { 
return "Hello (title) (person)" 
} 
return 
type 
greet("Mr.", "Paul") “Hello Mr. Paul"
Module 04 Slide 5 6 Hello24 Ltd. (c) 2014 
Nesting 
func greet(var person: String) -> String { 
func morningGreetings(person: String) -> String { 
return "Good morning (person)" 
} 
func afternoonGreetings(person: String) -> String { 
return "Good afternoon (person)" 
} 
let morning = true 
var greeting: (String) -> String 
if morning { 
greeting = morningGreetings 
} else { 
greeting = afternoonGreetings 
} 
return greeting(person) 
} 
greet("Paul")
Function as return type 
func greetingAt(hour: Int) -> (String) -> String { 
func morningGreeting(name: String) -> String { 
Module 04 Slide 5 7 Hello24 Ltd. (c) 2014 
return "Good morning (name)" 
} 
func afternoonGreeting(name: String) -> String { 
return "Good afternoon (name)" 
} 
return hour < 12 ? morningGreeting : afternoonGreeting 
} 
greetingAt(11)("Paul") 
greetingAt(14)("Paul") 
“Good morning Paul" 
“Good afternoon Paul"
Functions are Closures
Module 04 Slide 5 9 Hello24 Ltd. (c) 2014 
Blocks in Objective-C 
NSString *(^sayHello)(NSString *); 
sayHello = ^(NSString *name) { 
return [NSString stringWithFormat:@"Hello %@", name]; 
}; 
Person *theUser = [[Person alloc] initWithName:@"Paul"]; 
[theUser welcomeUserWithBlock:^(NSString *name) { 
NSLog(@"Hello %@", name); 
}];
Module 04 Slide 6 0 Hello24 Ltd. (c) 2014 
Blocks in Objective-C 
func greetWithMessage(name: String, 
message: (String) -> String) -> String { 
return message(name); 
} 
greetWithMessage("Paul", 
{ (name: String) -> String in 
return "Good morning (name)" 
} 
)
Module 04 Slide Hello24 Ltd. (c) 2014 
• global function 
• have name & don’t capture environment 
• nested function 
• have name & capture environment 
• closure expressions 
• no name & can capture environment 
61 
Types of Closures
7. Magic
Closures - Short Syntax 
func greetWithMessage(name: String, message: (String) -> String) -> String { 
Module 04 Slide 6 3 Hello24 Ltd. (c) 2014 
return message(name); 
} 
greetWithMessage("Paul", 
{ (name: String) -> String in 
return "Good morning (name)" 
} 
) 
greetWithMessage("Paul", { name in 
return "Good morning (name)" 
}) 
greetWithMessage("Paul", { 
return "Good morning ($0)" 
})
Module 04 Slide 6 4 Hello24 Ltd. (c) 2014 
Trailing closures 
func greetWithMessage(name: String, message: (String) -> String) -> String { 
return message(name); 
} 
greetWithMessage("Paul", { name in 
return "Good morning (name)" 
}) 
greetWithMessage("Paul") { name in 
return "Good morning (name)" 
} 
greetWithMessage("Paul") { return "Good morning ($0)" }
8. Unicode
8. Emoji
Module 02 Slide 6 7 Hello24 Ltd. (c) 2014 
Characters & Strings 
let dog = "" 
let fizz = "" 
let buzz = "" 
var fizzbuzz = fizz + buzz ""
Module 02 Slide 6 8 Hello24 Ltd. (c) 2014 
Character Viewer
Module 02 Slide Hello24 Ltd. (c) 2014 
let  = "dog" 
let  = "cat" 
let  = "ladybug" 
let ❄️ = "⛄️" 
69 
Emoji
Module 02 Slide 7 0 Hello24 Ltd. (c) 2014
Slide 7 1 Hello24 Ltd. (c) 2014
"ş" 
Module 02 Slide 7 2 Hello24 Ltd. (c) 2014 
Unicode 
let a = "u{103}" 
let sh = "u{15F}" 
"ă" 
"ş" 
Extended grapheme cluster 
ș = s + cedilla 
let cedilla = "u{327}" "̧" 
let sh2 = "u{73}u{327}" 
"u{15F}" == "u{73}u{327}" true
Module 02 Slide 7 3 Hello24 Ltd. (c) 2014 
Unicode 
let sh = "u{15F}" "ş" 
let realSh = "u{219}" "ș"
9. Playgrounds
Slide 7 6 Hello24 Ltd. (c) 2014 
New Playground
Slide 7 7 Hello24 Ltd. (c) 2014 
Empty Playground
Slide 7 8 Hello24 Ltd. (c) 2014 
Playground
Slide 7 9 Hello24 Ltd. (c) 2014 
Playground
Slide 8 0 Hello24 Ltd. (c) 2014 
Fibonacci
Slide 8 1 Hello24 Ltd. (c) 2014 
Fibonacci
Slide 8 2 Hello24 Ltd. (c) 2014 
Fibonacci
Slide 8 3 Hello24 Ltd. (c) 2014 
Playground - Timeline
Slide Hello24 Ltd. (c) 2014 
‣ Interactive experience 
‣ Immediate feedback 
‣ Watch code progression through loops 
‣ Easy way to 
‣ prototype 
‣ test snippets of code 
‣ CAREFUL! Executed automatically. 
84 
Playgrounds
10. Swift REPL
Slide 8 6 Hello24 Ltd. (c) 2014 
REPL 
Read–eval–print loop 
$ which swift 
/usr/bin/swift 
$ swift -version 
Swift version 1.1 (swift-600.0.54.20) 
Target: x86_64-apple-darwin14.0.0
Slide 8 7 Hello24 Ltd. (c) 2014 
man swift
Slide 8 8 Hello24 Ltd. (c) 2014 
swift -- help
$ swift 
Welcome to Swift! Type :help for assistance. 
1> 1 + 2 
$R0: Int = 3 
2> "once upon a time" 
$R1: String = "once upon a time" 
3> $R1 + " there were ($R0) bears" 
$R2: String = "once upon a time there were 3 bears" 
4> println($R2) 
once upon a time there were 3 bears 
Slide Hello24 Ltd. (c) 2014 
89 
REPL
‣ iOS 8 released yesterday 
‣ Swift is v.1.0 as of Sept 9th 
‣ Xcode 6.0.1 released yesterday 
‣ Apps written in Swift started being accepted on Sept 9th 
Slide Hello24 Ltd. (c) 2014 
90 
Resources
‣ iOS 8 released yesterday 
‣ Swift is v.1.0 as of Sept 9th 
‣ Xcode 6.0.1 released yesterday 
‣ Apps written in Swift started being accepted on Sept 9th 
Slide Hello24 Ltd. (c) 2014 
91 
Resources
10 reasons you’ll love Swift 
6.Functions - 1st class citizens 
7.Magic 
8.Unicode 
9.Playgrounds 
10.REPL 
Slide Hello24 Ltd. (c) 2014 
1.No C 
2.Modern 
3.Safety 
4.Optionals 
5.Mix & match 
92
Objective-C ➾ Swift
Slide 9 4 Hello24 Ltd. (c) 2014
One more thing…
WatchKit
Thank you! 
Paul Ardeleanu 
pa@h24.io 
@pardel 
© 2014 Hello24 Ltd. 
hello24.com

More Related Content

What's hot

What's hot (20)

C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
Functional Design Explained (David Sankel CppCon 2015)
Functional Design Explained (David Sankel CppCon 2015)Functional Design Explained (David Sankel CppCon 2015)
Functional Design Explained (David Sankel CppCon 2015)
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
What We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingWhat We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit Testing
 
ZIO Queue
ZIO QueueZIO Queue
ZIO Queue
 
Functional C++
Functional C++Functional C++
Functional C++
 
Berlin meetup
Berlin meetupBerlin meetup
Berlin meetup
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Eta
EtaEta
Eta
 
Qno 1 (d)
Qno 1 (d)Qno 1 (d)
Qno 1 (d)
 
Computer Practical XII
Computer Practical XIIComputer Practical XII
Computer Practical XII
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
 
Pure Future
Pure FuturePure Future
Pure Future
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
C programs
C programsC programs
C programs
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
The Vanishing Pattern: from iterators to generators in Python
The Vanishing Pattern: from iterators to generators in PythonThe Vanishing Pattern: from iterators to generators in Python
The Vanishing Pattern: from iterators to generators in Python
 
Machine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting ConcernsMachine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting Concerns
 

Similar to iOSNeXT.ro - 10 reasons you'll love Swift - Paul Ardeleanu

Similar to iOSNeXT.ro - 10 reasons you'll love Swift - Paul Ardeleanu (20)

Anti Object-Oriented Design Patterns
Anti Object-Oriented Design PatternsAnti Object-Oriented Design Patterns
Anti Object-Oriented Design Patterns
 
What's new in C# 6.0
What's new in C# 6.0What's new in C# 6.0
What's new in C# 6.0
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
 
JavaFX
JavaFXJavaFX
JavaFX
 
Effective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good PracticesEffective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good Practices
 
Algebra and Trigonometry 9th Edition Larson Solutions Manual
Algebra and Trigonometry 9th Edition Larson Solutions ManualAlgebra and Trigonometry 9th Edition Larson Solutions Manual
Algebra and Trigonometry 9th Edition Larson Solutions Manual
 
Progressive transpilation and the road to ES2015 in production
Progressive transpilation and the road to ES2015 in productionProgressive transpilation and the road to ES2015 in production
Progressive transpilation and the road to ES2015 in production
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle Groovy
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
Kotlin: maybe it's the right time
Kotlin: maybe it's the right timeKotlin: maybe it's the right time
Kotlin: maybe it's the right time
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effects
 
C++ Interface Versioning
C++ Interface VersioningC++ Interface Versioning
C++ Interface Versioning
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
What's new in AVR 12.0 and VS 2013
What's new in AVR 12.0 and VS 2013What's new in AVR 12.0 and VS 2013
What's new in AVR 12.0 and VS 2013
 
2020 03-26 - meet up - zparkio
2020 03-26 - meet up - zparkio2020 03-26 - meet up - zparkio
2020 03-26 - meet up - zparkio
 
Being Expressive in Code
Being Expressive in CodeBeing Expressive in Code
Being Expressive in Code
 

More from Paul Ardeleanu

My talk @ Timisoara Mobile Development Group February Meetup
My talk @ Timisoara Mobile Development Group February MeetupMy talk @ Timisoara Mobile Development Group February Meetup
My talk @ Timisoara Mobile Development Group February Meetup
Paul Ardeleanu
 
How to prototype your mobile apps
How to prototype your mobile appsHow to prototype your mobile apps
How to prototype your mobile apps
Paul Ardeleanu
 

More from Paul Ardeleanu (20)

Test or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOSTest or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOS
 
Test or Go Fishing - A guide on how to write better Swift for iOS
Test or Go Fishing - A guide on how to write better Swift for iOSTest or Go Fishing - A guide on how to write better Swift for iOS
Test or Go Fishing - A guide on how to write better Swift for iOS
 
Prototype your dream
Prototype your dreamPrototype your dream
Prototype your dream
 
Test or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOSTest or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOS
 
Architecting apps - Can we write better code by planning ahead?
Architecting apps - Can we write better code by planning ahead?Architecting apps - Can we write better code by planning ahead?
Architecting apps - Can we write better code by planning ahead?
 
iOSNeXT.ro - Scout mapping & navigation SDK for iOS developers - Zoltan Korosi
iOSNeXT.ro - Scout mapping & navigation SDK for iOS developers - Zoltan KorosiiOSNeXT.ro - Scout mapping & navigation SDK for iOS developers - Zoltan Korosi
iOSNeXT.ro - Scout mapping & navigation SDK for iOS developers - Zoltan Korosi
 
iOSNeXT.ro - Catwalk15 - Mark Filipas
iOSNeXT.ro - Catwalk15 - Mark FilipasiOSNeXT.ro - Catwalk15 - Mark Filipas
iOSNeXT.ro - Catwalk15 - Mark Filipas
 
iOSNeXT.ro - Lessons learnt as Indie Developer in Romania - Alexandru Iliescu
iOSNeXT.ro - Lessons learnt as Indie Developer in Romania - Alexandru IliescuiOSNeXT.ro - Lessons learnt as Indie Developer in Romania - Alexandru Iliescu
iOSNeXT.ro - Lessons learnt as Indie Developer in Romania - Alexandru Iliescu
 
7 things one should learn from iOS
7 things one should learn from iOS7 things one should learn from iOS
7 things one should learn from iOS
 
iOScon 2014
iOScon 2014 iOScon 2014
iOScon 2014
 
To swiftly go where no OS has gone before
To swiftly go where no OS has gone beforeTo swiftly go where no OS has gone before
To swiftly go where no OS has gone before
 
iOS Developer Overview - DevWeek 2014
iOS Developer Overview - DevWeek 2014iOS Developer Overview - DevWeek 2014
iOS Developer Overview - DevWeek 2014
 
Prototyping saves your bacon
Prototyping saves your baconPrototyping saves your bacon
Prototyping saves your bacon
 
My talk @ Timisoara Mobile Development Group February Meetup
My talk @ Timisoara Mobile Development Group February MeetupMy talk @ Timisoara Mobile Development Group February Meetup
My talk @ Timisoara Mobile Development Group February Meetup
 
How to prototype your mobile apps
How to prototype your mobile appsHow to prototype your mobile apps
How to prototype your mobile apps
 
Native vs html5
Native vs html5Native vs html5
Native vs html5
 
Prototyping your iPhone/iPad app
Prototyping your iPhone/iPad appPrototyping your iPhone/iPad app
Prototyping your iPhone/iPad app
 
Whats new in iOS5
Whats new in iOS5Whats new in iOS5
Whats new in iOS5
 
There is no spoon - iPhone vs. iPad
There is no spoon - iPhone vs. iPadThere is no spoon - iPhone vs. iPad
There is no spoon - iPhone vs. iPad
 
The Adventure - From idea to the iPhone
The Adventure - From idea to the iPhoneThe Adventure - From idea to the iPhone
The Adventure - From idea to the iPhone
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 

iOSNeXT.ro - 10 reasons you'll love Swift - Paul Ardeleanu

  • 1. 10 reasons you'll love Swift Paul Ardeleanu © 2014 Hello24 Ltd. hello24.com
  • 2.
  • 4.
  • 5. TIOBE Index for Nov 2014 Slide 5 Hello24 Ltd. (c) 2014
  • 6. TIOBE Index for Nov 2014 Slide 6 Hello24 Ltd. (c) 2014
  • 7. Why a new language?
  • 8. Slide 8 Hello24 Ltd. (c) 2014 AAPL
  • 9. Slide 9 Hello24 Ltd. (c) 2014 Products
  • 10. Slide 1 0 Hello24 Ltd. (c) 2014 Software
  • 11. Slide 1 1 Hello24 Ltd. (c) 2014 App Stores
  • 12. Slide 1 2 Hello24 Ltd. (c) 2014 Apps
  • 14. Slide Hello24 Ltd. (c) 2014 ‣ maximise the number of developers ‣ keeping existing developers happy 14 2 ways…
  • 15. Slide Hello24 Ltd. (c) 2014 ‣ 30 year old language ‣ drastically different from other languages ‣ not entirely future-proof 15 Objective-C
  • 16. How did this happen?
  • 17. LLVM & Clang gcc => llvm-gcc => llvm
  • 18.
  • 19. Swift Objective-C without C Slide Hello24 Ltd. (c) 2014 19 Objective-C is to Swift == cat is to cattle
  • 20. 10 reasons you'll love Swift
  • 22. Slide 2 2 Hello24 Ltd. (c) 2014 No main( ) function
  • 23. Slide 2 3 Hello24 Ltd. (c) 2014 No [, ] or ;
  • 25. Module 02 Slide Hello24 Ltd. (c) 2014 let http404Error = (404, "Not Found") 25 Tuples let x = 1 let y = 2 let point = (x, y) (.0 1, .1 2) point.0 1 let origin = (x: 200, y: 100) origin.y (.0 200, .1 100) 100
  • 26. Module 02 Slide Hello24 Ltd. (c) 2014 // Original var fibonacci = 1 var prev = 0 while fibonacci < 100 { var prev_tmp = fibonacci fibonacci += prev prev = prev_tmp println(fibonacci) } 26 Fibonacci Tuples // tuples var fibonacci = 1 var prev = 0 while fibonacci < 100 { (prev, fibonacci) = (fibonacci, fibonacci + prev) println(fibonacci) }
  • 27. Nil coalescing operator var b = a ?? "default value" Module 02 Slide 2 7 Hello24 Ltd. (c) 2014
  • 29. Slide Hello24 Ltd. (c) 2014 let theAnswer = 42 29 Constants & variables var numberBooks = 1 var numberBooks: Int = 1
  • 30. Safety - no implicit conversion Slide 3 0 Hello24 Ltd. (c) 2014 let theAnswer2 = 42 let trueAnswer = Double(theAnswer) + 0.0001 let aNumber:UInt8 = 42 let anotherNumber:Int64 = Int64(aNumber)
  • 31. Slide 3 1 Hello24 Ltd. (c) 2014 Safety - switch switch (aNumber % 3, aNumber % 5 ) { case (0, 0): println("fizzbuzz") case (0, _): println("fizz") case (_, 0): println("buzz") default: println(aNumber) }
  • 32. Module 06 Slide 3 2 Hello24 Ltd. (c) 2014 Classes vs. Structures struct Point { var x = 0 var y = 0 static var counter = 0 static let origin = Point() var description: String { get { switch (point.x, point.y) { case (let 0, 0): return "origin" case (let x, 0): return "on the y axis - x = (case (0, let y): return "on the x axis - y = (default: return "(point.x)x(point.y)" } } } func distanceToOrigin() -> Double { return … } } class Fruit { var color: String var diameter: Int var area: Double { get { return self.width * self.height } set(newValue) { self.width = sqrt(newValue) self.height = sqrt(newValue) } } init(color: String, diameter: Int) { self.color = color self.diameter = diameter } func area() -> Double { return self.width * self.height } }
  • 33. Module 06 Slide 3 3 Hello24 Ltd. (c) 2014 Classes vs. Structures Classes Structs passed by reference value inheritance ✔ ✘ initializers must be defined auto-generated member-wise initialiser deinitializer ✔ ✘ introspection ✔ ✘ ideal for complex data relatively simple data *
  • 34. Module 05 Slide 3 4 Hello24 Ltd. (c) 2014 Value type (Structures) var point1 = Point(x: 100, y: 200) var point2 = point1 x: 100 point1.x = 120 point1 y : 200 x: 100 point2 y : 200
  • 35. Module 05 Slide 3 5 Hello24 Ltd. (c) 2014 Value type (Structures) var point1 = Point(x: 100, y: 200) var point2 = point1 x: 120 point1.x = 120 point1 y : 200 x: 100 point2 y : 200
  • 36. Module 06 Slide 3 6 Hello24 Ltd. (c) 2014 Reference type (Classes) var rectangle1 = Rect() rectangle1.width = 100 var rectangle2 = rectangle1 rectangle2.width = 200 width: 100 rectangle1 height: 0 rectangle2
  • 37. Module 06 Slide 3 7 Hello24 Ltd. (c) 2014 Reference type (Classes) var rectangle1 = Rect() rectangle1.width = 100 var rectangle2 = rectangle1 rectangle2.width = 200 width: 200 rectangle1 height: 0 rectangle2
  • 38. nil
  • 39.
  • 41. ❗️ Module 02 Slide 4 1 Hello24 Ltd. (c) 2014 Optionals var answer: Int = 42 var theAnswer: Int = nil var theAnswer: Int? ✔ theAnswer = 42 nil {Some 42}
  • 42. Optionals == Schrödinger’s cat Can either: ‣ be nil ‣ contain a value Module 02 Slide 4 2 Hello24 Ltd. (c) 2014
  • 43. Module 02 Slide 4 3 Hello24 Ltd. (c) 2014 Using an optional var theAnswer: Int? if theAnswer != nil { var x = 4 + theAnswer } ❗️
  • 44. Module 02 Slide 4 4 Hello24 Ltd. (c) 2014 Forced Unwrapping var theAnswer: Int? if theAnswer != nil { var x = 4 + theAnswer! } ✔
  • 45. Module 02 Slide 4 5 Hello24 Ltd. (c) 2014 Optional binding if theAnswer != nil { if let answer = theAnswer { var x = 4 + answer } var x = 4 + theAnswer! } no !
  • 46. Module 02 Slide 4 6 Hello24 Ltd. (c) 2014 Optionals var theAnswer: Int? if theAnswer != nil { var x = 4 + theAnswer! } theAnswer!
  • 47. Module 02 Slide 4 7 Hello24 Ltd. (c) 2014 Optionals var theAnswer = 42 var theAnswer: Int? var theAnswer: Int! - always has a value - type can be inferred - either nil or has a value - must be unwrapped - nil until first assignment - assumed to always have a value
  • 48. Nil coalescing operator Module 02 Slide 4 8 Hello24 Ltd. (c) 2014 var theAnswer: Int? var x = theAnswer ?? 12 equivalent to: var x = (theAnswer != nil) ? theAnswer! : 12
  • 49. 5. Mix & match
  • 50. Slide 5 0 Hello24 Ltd. (c) 2014 Swift project
  • 51. Slide 5 1 Hello24 Ltd. (c) 2014 Bridging
  • 52. Slide 5 2 Hello24 Ltd. (c) 2014 Bridging
  • 53. Slide 5 3 Hello24 Ltd. (c) 2014 Bridging class STDataObject: NSManagedObject { @NSManaged var uuid: String? @NSManaged var sync_uuid: String? @NSManaged var is_active: NSNumber class func managedObjectContext() -> NSManagedObjectContext? { var appDelegate = UIApplication.sharedApplication().delegate as AppDelegate return appDelegate.managedObjectContext }
  • 54. 6. Functions as first class citizens
  • 55. Module 04 Slide 5 5 Hello24 Ltd. (c) 2014 Function structure function name parameter name parameter type func greet(title: String, person: String) -> String { return "Hello (title) (person)" } return type greet("Mr.", "Paul") “Hello Mr. Paul"
  • 56. Module 04 Slide 5 6 Hello24 Ltd. (c) 2014 Nesting func greet(var person: String) -> String { func morningGreetings(person: String) -> String { return "Good morning (person)" } func afternoonGreetings(person: String) -> String { return "Good afternoon (person)" } let morning = true var greeting: (String) -> String if morning { greeting = morningGreetings } else { greeting = afternoonGreetings } return greeting(person) } greet("Paul")
  • 57. Function as return type func greetingAt(hour: Int) -> (String) -> String { func morningGreeting(name: String) -> String { Module 04 Slide 5 7 Hello24 Ltd. (c) 2014 return "Good morning (name)" } func afternoonGreeting(name: String) -> String { return "Good afternoon (name)" } return hour < 12 ? morningGreeting : afternoonGreeting } greetingAt(11)("Paul") greetingAt(14)("Paul") “Good morning Paul" “Good afternoon Paul"
  • 59. Module 04 Slide 5 9 Hello24 Ltd. (c) 2014 Blocks in Objective-C NSString *(^sayHello)(NSString *); sayHello = ^(NSString *name) { return [NSString stringWithFormat:@"Hello %@", name]; }; Person *theUser = [[Person alloc] initWithName:@"Paul"]; [theUser welcomeUserWithBlock:^(NSString *name) { NSLog(@"Hello %@", name); }];
  • 60. Module 04 Slide 6 0 Hello24 Ltd. (c) 2014 Blocks in Objective-C func greetWithMessage(name: String, message: (String) -> String) -> String { return message(name); } greetWithMessage("Paul", { (name: String) -> String in return "Good morning (name)" } )
  • 61. Module 04 Slide Hello24 Ltd. (c) 2014 • global function • have name & don’t capture environment • nested function • have name & capture environment • closure expressions • no name & can capture environment 61 Types of Closures
  • 63. Closures - Short Syntax func greetWithMessage(name: String, message: (String) -> String) -> String { Module 04 Slide 6 3 Hello24 Ltd. (c) 2014 return message(name); } greetWithMessage("Paul", { (name: String) -> String in return "Good morning (name)" } ) greetWithMessage("Paul", { name in return "Good morning (name)" }) greetWithMessage("Paul", { return "Good morning ($0)" })
  • 64. Module 04 Slide 6 4 Hello24 Ltd. (c) 2014 Trailing closures func greetWithMessage(name: String, message: (String) -> String) -> String { return message(name); } greetWithMessage("Paul", { name in return "Good morning (name)" }) greetWithMessage("Paul") { name in return "Good morning (name)" } greetWithMessage("Paul") { return "Good morning ($0)" }
  • 67. Module 02 Slide 6 7 Hello24 Ltd. (c) 2014 Characters & Strings let dog = "" let fizz = "" let buzz = "" var fizzbuzz = fizz + buzz ""
  • 68. Module 02 Slide 6 8 Hello24 Ltd. (c) 2014 Character Viewer
  • 69. Module 02 Slide Hello24 Ltd. (c) 2014 let  = "dog" let  = "cat" let  = "ladybug" let ❄️ = "⛄️" 69 Emoji
  • 70. Module 02 Slide 7 0 Hello24 Ltd. (c) 2014
  • 71. Slide 7 1 Hello24 Ltd. (c) 2014
  • 72. "ş" Module 02 Slide 7 2 Hello24 Ltd. (c) 2014 Unicode let a = "u{103}" let sh = "u{15F}" "ă" "ş" Extended grapheme cluster ș = s + cedilla let cedilla = "u{327}" "̧" let sh2 = "u{73}u{327}" "u{15F}" == "u{73}u{327}" true
  • 73. Module 02 Slide 7 3 Hello24 Ltd. (c) 2014 Unicode let sh = "u{15F}" "ş" let realSh = "u{219}" "ș"
  • 75.
  • 76. Slide 7 6 Hello24 Ltd. (c) 2014 New Playground
  • 77. Slide 7 7 Hello24 Ltd. (c) 2014 Empty Playground
  • 78. Slide 7 8 Hello24 Ltd. (c) 2014 Playground
  • 79. Slide 7 9 Hello24 Ltd. (c) 2014 Playground
  • 80. Slide 8 0 Hello24 Ltd. (c) 2014 Fibonacci
  • 81. Slide 8 1 Hello24 Ltd. (c) 2014 Fibonacci
  • 82. Slide 8 2 Hello24 Ltd. (c) 2014 Fibonacci
  • 83. Slide 8 3 Hello24 Ltd. (c) 2014 Playground - Timeline
  • 84. Slide Hello24 Ltd. (c) 2014 ‣ Interactive experience ‣ Immediate feedback ‣ Watch code progression through loops ‣ Easy way to ‣ prototype ‣ test snippets of code ‣ CAREFUL! Executed automatically. 84 Playgrounds
  • 86. Slide 8 6 Hello24 Ltd. (c) 2014 REPL Read–eval–print loop $ which swift /usr/bin/swift $ swift -version Swift version 1.1 (swift-600.0.54.20) Target: x86_64-apple-darwin14.0.0
  • 87. Slide 8 7 Hello24 Ltd. (c) 2014 man swift
  • 88. Slide 8 8 Hello24 Ltd. (c) 2014 swift -- help
  • 89. $ swift Welcome to Swift! Type :help for assistance. 1> 1 + 2 $R0: Int = 3 2> "once upon a time" $R1: String = "once upon a time" 3> $R1 + " there were ($R0) bears" $R2: String = "once upon a time there were 3 bears" 4> println($R2) once upon a time there were 3 bears Slide Hello24 Ltd. (c) 2014 89 REPL
  • 90. ‣ iOS 8 released yesterday ‣ Swift is v.1.0 as of Sept 9th ‣ Xcode 6.0.1 released yesterday ‣ Apps written in Swift started being accepted on Sept 9th Slide Hello24 Ltd. (c) 2014 90 Resources
  • 91. ‣ iOS 8 released yesterday ‣ Swift is v.1.0 as of Sept 9th ‣ Xcode 6.0.1 released yesterday ‣ Apps written in Swift started being accepted on Sept 9th Slide Hello24 Ltd. (c) 2014 91 Resources
  • 92. 10 reasons you’ll love Swift 6.Functions - 1st class citizens 7.Magic 8.Unicode 9.Playgrounds 10.REPL Slide Hello24 Ltd. (c) 2014 1.No C 2.Modern 3.Safety 4.Optionals 5.Mix & match 92
  • 94. Slide 9 4 Hello24 Ltd. (c) 2014
  • 97. Thank you! Paul Ardeleanu pa@h24.io @pardel © 2014 Hello24 Ltd. hello24.com