SlideShare a Scribd company logo
1 of 31
Swift 
Apple’s New Programming Language 
Sasha Goldshtein 
CTO, Sela Group 
blog.sashag.net @goldshtn 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Apple WWDC Announcements 
• iOS 8 and OS X Yosemite 
• Xcode 6 
• Swift 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Minus Bazillion Points 
“Every feature starts out in the hole by 100 
points, which means that it has to have a 
significant net positive effect on the overall 
package for it to make it into the language.” 
– Eric Gunnerson, C# compiler team 
If a language feature starts at -100 points, 
where does a new language start?! 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Objective-C Popularity 
• Objective-C owes all its popularity to the 
meteoric rise of the iPhone 
App Store introduced 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
What’s Wrong with Objective-C 
Exhibit One 
// Ignore the horrible syntax for a second. 
// But here's the charmer: 
// 1) if 'str' is null, we return NSNotFound (232-1) 
// 2) if 'arr' is null, we return 0 
+ (NSUInteger)indexOfString:(NSString *)str 
inArray:(NSArray *)arr 
{ 
return [arr indexOfObject:str]; 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
What’s Wrong with Objective-C 
Exhibit Two 
// This compiles and crashes at runtime with: 
// "-[__NSArrayI addObject:]: unrecognized selector 
// sent to instance 0x7a3141c0" 
NSMutableArray *array = [NSArray array]; 
[array addObject:@"hello"]; 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
What’s Wrong with Objective-C 
Exhibit Three 
NSMutableArray *array = [NSMutableArray array]; 
[array addObject:@"hello"]; 
[array addObject:@17]; 
// This compiles just fine 
NSString *string = array[1]; // Yes, the "17" 
// This works and prints 17 
NSLog(@"%@", string); 
// But this crashes 
NSLog(@"%@", 
[string stringByAppendingString:@"hmm"]); 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Swift Language Principles 
• Clean and modern 
• Type-safe and generic 
• Extensible 
• Functional 
• Productive 
• Compiled to native 
• Seamlessly interops with Objective-C 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Why Not an Existing Language? 
• Good philosophical question 
• If you want some more philosophy: 
http://s.sashag.net/why-swift 
We will now review some of the interesting 
language decisions, which make Swift 
different from mainstream languages 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Variables and Constants 
let size = 42 
let name = "Dave" 
var address = "14 Franklin Way" 
address = "16 Calgary Drive" 
var city: String 
city = "London" 
var pi: Double = 3.14 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Strings and Arrays 
var fullAddress = city + " " + address 
println("(name)'s at (city.capitalizedString)") 
var customers = ["Dave", "Kate", "Jack"] 
var addresses = [String]() 
addresses += fullAddress 
if customers[2].hasPrefix("Ja") { 
customers.removeAtIndex(2) 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Dictionaries 
var orderSummary = [ 
"Dave": 11000, 
"Kate": 14000, 
"Jack": 13500 
] 
orderSummary["Kate"] = 17500 
for (customer, orders) in orderSummary { 
println("(customer) -> (orders)") 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Null 
“I call it my billion-dollar mistake. It was the 
invention of the null reference in 1965. […] I 
couldn't resist the temptation to put in a null 
reference, simply because it was so easy to 
implement. This has led to innumerable 
errors, vulnerabilities, and system crashes, 
which have probably caused a billion dollars 
of pain and damage in the last forty years.” 
– Sir Charles Antony Richard Hoare, 
2009 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Optional Types 
var myName: String 
myName = nil // Does not compile! 
var jeffsOrders: Int? 
jeffsOrders = orderSummary["Jeff”] 
if jeffsOrders { 
let orders: Int = jeffsOrders! 
} 
var customerName: String? = getCustomer() 
println("name: (customerName?.uppercaseString)") 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Pattern Matching 
switch milesFlown["Jeff"]! { 
case 0..<25000: 
println("Jeff is a Premier member") 
case 25000..<50000: 
println("Jeff is a Silver member") 
case 50000..<75000: 
println("Jeff is a Gold member") 
case 75000..<100000: 
println("Jeff is a Platinum member") 
default: 
println("Jeff is an Elite member") 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Pattern Matching 
switch reservation.fareClass { 
case "F", "A", "J", "C": 
milesBonus = 2.5 // business/first 
case "Y", "B": 
milesBonus = 2.0 // full-fare economy 
case "M", "H": 
milesBonus = 1.5 // top-tier discount economy 
case let fc where fc.hasPrefix("Z"): 
milesBonus = 0 // upgrades don't earn miles 
default: 
milesBonus = 1.0 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Functions and Tuples 
func square(x: Int) -> Int { return x * x } 
func powers(x: Int) -> (Int, Int, Int) { 
return (x, x*x, x*x*x) 
} 
// The first tuple element is ignored 
let (_, square, cube) = powers(42) 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Closures 
func countIf(arr: [Int], pred: (Int) -> Bool) { 
var count = 0 
for n in arr { if pred(n) { ++count } } 
return count 
} 
countIf([1, 2, 3, 4], { n in n % 2 == 0 }) 
var squares = [17, 3, 11, 5, 7].map({ x in x * x }) 
sort(&squares, { a, b in a > b }) 
sort(&squares) { a, b in a > b } 
sort(&squares) { $0 > $1 } 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Swift REPL 
DEMO 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Classes 
class FrequentFlier { 
let name: String 
var miles: Double = 0 
init(name: String) { 
self.name = name 
} 
func addMileage(fareClass: String, dist: Int) { 
miles += bonus(fareClass) * Double(dist) 
} 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Custom Properties and 
Observers 
class MileageStatus { 
var miles: Double = 0.0 { 
willSet { 
assert(newValue >= miles) 
// can't decrease one's mileage 
} 
} 
var status: String { 
get { switch miles { /* ... */ } } 
} 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Smart Enums 
enum MemberLevel { 
case Silver 
case Gold 
case Platinum 
func milesRequired() -> Int { 
switch self { 
case .Silver: return 25000 
case .Gold: return 50000 
case .Platinum: return 75000 
} 
} 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Stateful Enums 
enum HttpResponse { 
case Success(body: String) 
case Error(description: String, statusCode: Int) 
} 
switch fakeHttpRequest("example.org") { 
case let .Error(desc, status) where status >= 500: 
println("internal server error: (desc)") 
case let .Error(desc, status): 
println("error (status) = (desc)") 
case .Success(let body): 
println("success, body = (body)") 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Extensions 
extension Int { 
var absoluteValue: Int { 
get { return abs(self) } 
} 
func times(action: () -> Void) { 
for _ in 1...self { 
action() 
} 
} 
} 
5.times { println("hello") } 
println((-5).absoluteValue) 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Generics 
class Queue<T> { 
var items = [T]() 
var depth: Int { 
get { return items.count } 
} 
func enqueue(item: T) { 
items.append(item) 
} 
func dequeue() -> T { 
return items.removeAtIndex(0) 
} 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Operators 
struct Complex { 
var r: Double, i: Double 
func add(z: Complex) -> Complex { 
return Complex(r: r+z.r, i: i+z.i) 
} 
} 
@infix func +(z1: Complex, z2: Complex) -> Complex { 
return z1.add(z2) 
} 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Custom Operators (Oh My!) 
operator prefix &*^%!~ {} 
@prefix func &*^%!~(s: String) -> String { 
return s.uppercaseString 
} 
operator infix ^^ { associativity left } 
@infix func ^^(a: Double, b: Double) -> Double { 
return pow(a, b) 
} 
println(&*^%!~"hello") // prints "HELLO" 
println(2.0^^4.0) // prints 8.0 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Swift and Objective-C 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Building an iOS app with Swift 
DEMO 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Wrapping Up 
• Most iOS developers are extremely 
excited about Swift 
• Swift has a much smoother learning curve 
and fixes many Objective-C mistakes 
• For the foreseeable future though, we will 
still use both languages 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift
Sasha Goldshtein 
blog.sashag.net 
@goldshtn 
s.sashag.net/sa-swift 
Thank You! 
Join the conversation on Twitter: @SoftArchConf #SA2014 
This presentation: http://s.sashag.net/sa-swift

More Related Content

What's hot

No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)Pixie Labs
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealTzung-Bi Shih
 
Trying to learn C# (NDC Oslo 2019)
Trying to learn C# (NDC Oslo 2019)Trying to learn C# (NDC Oslo 2019)
Trying to learn C# (NDC Oslo 2019)Patricia Aas
 
Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)James Titcumb
 
Model Serving via Pulsar Functions
Model Serving via Pulsar FunctionsModel Serving via Pulsar Functions
Model Serving via Pulsar FunctionsArun Kejariwal
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers ToolboxStefan
 
Reliability Patterns for Fun and Profit
Reliability Patterns for Fun and ProfitReliability Patterns for Fun and Profit
Reliability Patterns for Fun and ProfitLuis Mineiro
 
HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1Linaro
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab FileKandarp Tiwari
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manualNaveen Kumar
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil Witecki
 
Lego: A brick system build by scala
Lego: A brick system build by scalaLego: A brick system build by scala
Lego: A brick system build by scalalunfu zhong
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)charsbar
 
{{components deepDive=true}}
{{components deepDive=true}}{{components deepDive=true}}
{{components deepDive=true}}raytiley
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manualPrabhu D
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semesterDOSONKA Group
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Tom Paulus
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart PointersCarlo Pescio
 
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...dantleech
 

What's hot (20)

No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the Seal
 
Trying to learn C# (NDC Oslo 2019)
Trying to learn C# (NDC Oslo 2019)Trying to learn C# (NDC Oslo 2019)
Trying to learn C# (NDC Oslo 2019)
 
Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)
 
Model Serving via Pulsar Functions
Model Serving via Pulsar FunctionsModel Serving via Pulsar Functions
Model Serving via Pulsar Functions
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 
Reliability Patterns for Fun and Profit
Reliability Patterns for Fun and ProfitReliability Patterns for Fun and Profit
Reliability Patterns for Fun and Profit
 
HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, code
 
Lego: A brick system build by scala
Lego: A brick system build by scalaLego: A brick system build by scala
Lego: A brick system build by scala
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
{{components deepDive=true}}
{{components deepDive=true}}{{components deepDive=true}}
{{components deepDive=true}}
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
 
Q 1
Q 1Q 1
Q 1
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers
 
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
 

Similar to Apple's New Programming Language Swift Highlights

Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015Gil Fink
 
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTechNETFest
 
Lift Presentation at DuSE VI
Lift Presentation at DuSE VILift Presentation at DuSE VI
Lift Presentation at DuSE VIPeter Robinett
 
Best practices for crafting high quality PHP apps (php[world] 2019)
Best practices for crafting high quality PHP apps (php[world] 2019)Best practices for crafting high quality PHP apps (php[world] 2019)
Best practices for crafting high quality PHP apps (php[world] 2019)James Titcumb
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTechAntya Dev
 
Introduction to iPhone Development
Introduction to iPhone DevelopmentIntroduction to iPhone Development
Introduction to iPhone DevelopmentDermot Daly
 
Introduction to iPhone Development
Introduction to iPhone DevelopmentIntroduction to iPhone Development
Introduction to iPhone Developmentdermdaly
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonAlex Payne
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Paulo Morgado
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)James Titcumb
 

Similar to Apple's New Programming Language Swift Highlights (20)

Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015
 
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
 
Lift Presentation at DuSE VI
Lift Presentation at DuSE VILift Presentation at DuSE VI
Lift Presentation at DuSE VI
 
Best practices for crafting high quality PHP apps (php[world] 2019)
Best practices for crafting high quality PHP apps (php[world] 2019)Best practices for crafting high quality PHP apps (php[world] 2019)
Best practices for crafting high quality PHP apps (php[world] 2019)
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
 
Introduction to iPhone Development
Introduction to iPhone DevelopmentIntroduction to iPhone Development
Introduction to iPhone Development
 
Introduction to iPhone Development
Introduction to iPhone DevelopmentIntroduction to iPhone Development
Introduction to iPhone Development
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Akka http 2
Akka http 2Akka http 2
Akka http 2
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 

More from Sasha Goldshtein

Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing LandscapeSasha Goldshtein
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerSasha Goldshtein
 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF AbyssSasha Goldshtein
 
Visual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkVisual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkSasha Goldshtein
 
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinC# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinSasha Goldshtein
 
Modern Backends for Mobile Apps
Modern Backends for Mobile AppsModern Backends for Mobile Apps
Modern Backends for Mobile AppsSasha Goldshtein
 
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Sasha Goldshtein
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionSasha Goldshtein
 
Delivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesDelivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesSasha Goldshtein
 
Building Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendBuilding Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendSasha Goldshtein
 
Building iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesBuilding iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesSasha Goldshtein
 
Attacking Web Applications
Attacking Web ApplicationsAttacking Web Applications
Attacking Web ApplicationsSasha Goldshtein
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile ServicesSasha Goldshtein
 
First Steps in Android Development
First Steps in Android DevelopmentFirst Steps in Android Development
First Steps in Android DevelopmentSasha Goldshtein
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS DevelopmentSasha Goldshtein
 

More from Sasha Goldshtein (20)

Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF Primer
 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF Abyss
 
Visual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkVisual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET Framework
 
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinC# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
 
Modern Backends for Mobile Apps
Modern Backends for Mobile AppsModern Backends for Mobile Apps
Modern Backends for Mobile Apps
 
.NET Debugging Workshop
.NET Debugging Workshop.NET Debugging Workshop
.NET Debugging Workshop
 
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and Production
 
Introduction to RavenDB
Introduction to RavenDBIntroduction to RavenDB
Introduction to RavenDB
 
State of the Platforms
State of the PlatformsState of the Platforms
State of the Platforms
 
Delivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesDelivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in Minutes
 
Building Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendBuilding Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET Backend
 
Building iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesBuilding iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile Services
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
 
What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
 
Attacking Web Applications
Attacking Web ApplicationsAttacking Web Applications
Attacking Web Applications
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile Services
 
First Steps in Android Development
First Steps in Android DevelopmentFirst Steps in Android Development
First Steps in Android Development
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS Development
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Apple's New Programming Language Swift Highlights

  • 1. Swift Apple’s New Programming Language Sasha Goldshtein CTO, Sela Group blog.sashag.net @goldshtn Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 2. Apple WWDC Announcements • iOS 8 and OS X Yosemite • Xcode 6 • Swift Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 3. Minus Bazillion Points “Every feature starts out in the hole by 100 points, which means that it has to have a significant net positive effect on the overall package for it to make it into the language.” – Eric Gunnerson, C# compiler team If a language feature starts at -100 points, where does a new language start?! Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 4. Objective-C Popularity • Objective-C owes all its popularity to the meteoric rise of the iPhone App Store introduced Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 5. What’s Wrong with Objective-C Exhibit One // Ignore the horrible syntax for a second. // But here's the charmer: // 1) if 'str' is null, we return NSNotFound (232-1) // 2) if 'arr' is null, we return 0 + (NSUInteger)indexOfString:(NSString *)str inArray:(NSArray *)arr { return [arr indexOfObject:str]; } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 6. What’s Wrong with Objective-C Exhibit Two // This compiles and crashes at runtime with: // "-[__NSArrayI addObject:]: unrecognized selector // sent to instance 0x7a3141c0" NSMutableArray *array = [NSArray array]; [array addObject:@"hello"]; Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 7. What’s Wrong with Objective-C Exhibit Three NSMutableArray *array = [NSMutableArray array]; [array addObject:@"hello"]; [array addObject:@17]; // This compiles just fine NSString *string = array[1]; // Yes, the "17" // This works and prints 17 NSLog(@"%@", string); // But this crashes NSLog(@"%@", [string stringByAppendingString:@"hmm"]); Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 8. Swift Language Principles • Clean and modern • Type-safe and generic • Extensible • Functional • Productive • Compiled to native • Seamlessly interops with Objective-C Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 9. Why Not an Existing Language? • Good philosophical question • If you want some more philosophy: http://s.sashag.net/why-swift We will now review some of the interesting language decisions, which make Swift different from mainstream languages Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 10. Variables and Constants let size = 42 let name = "Dave" var address = "14 Franklin Way" address = "16 Calgary Drive" var city: String city = "London" var pi: Double = 3.14 Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 11. Strings and Arrays var fullAddress = city + " " + address println("(name)'s at (city.capitalizedString)") var customers = ["Dave", "Kate", "Jack"] var addresses = [String]() addresses += fullAddress if customers[2].hasPrefix("Ja") { customers.removeAtIndex(2) } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 12. Dictionaries var orderSummary = [ "Dave": 11000, "Kate": 14000, "Jack": 13500 ] orderSummary["Kate"] = 17500 for (customer, orders) in orderSummary { println("(customer) -> (orders)") } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 13. Null “I call it my billion-dollar mistake. It was the invention of the null reference in 1965. […] I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.” – Sir Charles Antony Richard Hoare, 2009 Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 14. Optional Types var myName: String myName = nil // Does not compile! var jeffsOrders: Int? jeffsOrders = orderSummary["Jeff”] if jeffsOrders { let orders: Int = jeffsOrders! } var customerName: String? = getCustomer() println("name: (customerName?.uppercaseString)") Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 15. Pattern Matching switch milesFlown["Jeff"]! { case 0..<25000: println("Jeff is a Premier member") case 25000..<50000: println("Jeff is a Silver member") case 50000..<75000: println("Jeff is a Gold member") case 75000..<100000: println("Jeff is a Platinum member") default: println("Jeff is an Elite member") } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 16. Pattern Matching switch reservation.fareClass { case "F", "A", "J", "C": milesBonus = 2.5 // business/first case "Y", "B": milesBonus = 2.0 // full-fare economy case "M", "H": milesBonus = 1.5 // top-tier discount economy case let fc where fc.hasPrefix("Z"): milesBonus = 0 // upgrades don't earn miles default: milesBonus = 1.0 } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 17. Functions and Tuples func square(x: Int) -> Int { return x * x } func powers(x: Int) -> (Int, Int, Int) { return (x, x*x, x*x*x) } // The first tuple element is ignored let (_, square, cube) = powers(42) Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 18. Closures func countIf(arr: [Int], pred: (Int) -> Bool) { var count = 0 for n in arr { if pred(n) { ++count } } return count } countIf([1, 2, 3, 4], { n in n % 2 == 0 }) var squares = [17, 3, 11, 5, 7].map({ x in x * x }) sort(&squares, { a, b in a > b }) sort(&squares) { a, b in a > b } sort(&squares) { $0 > $1 } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 19. Swift REPL DEMO Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 20. Classes class FrequentFlier { let name: String var miles: Double = 0 init(name: String) { self.name = name } func addMileage(fareClass: String, dist: Int) { miles += bonus(fareClass) * Double(dist) } } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 21. Custom Properties and Observers class MileageStatus { var miles: Double = 0.0 { willSet { assert(newValue >= miles) // can't decrease one's mileage } } var status: String { get { switch miles { /* ... */ } } } } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 22. Smart Enums enum MemberLevel { case Silver case Gold case Platinum func milesRequired() -> Int { switch self { case .Silver: return 25000 case .Gold: return 50000 case .Platinum: return 75000 } } } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 23. Stateful Enums enum HttpResponse { case Success(body: String) case Error(description: String, statusCode: Int) } switch fakeHttpRequest("example.org") { case let .Error(desc, status) where status >= 500: println("internal server error: (desc)") case let .Error(desc, status): println("error (status) = (desc)") case .Success(let body): println("success, body = (body)") } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 24. Extensions extension Int { var absoluteValue: Int { get { return abs(self) } } func times(action: () -> Void) { for _ in 1...self { action() } } } 5.times { println("hello") } println((-5).absoluteValue) Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 25. Generics class Queue<T> { var items = [T]() var depth: Int { get { return items.count } } func enqueue(item: T) { items.append(item) } func dequeue() -> T { return items.removeAtIndex(0) } } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 26. Operators struct Complex { var r: Double, i: Double func add(z: Complex) -> Complex { return Complex(r: r+z.r, i: i+z.i) } } @infix func +(z1: Complex, z2: Complex) -> Complex { return z1.add(z2) } Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 27. Custom Operators (Oh My!) operator prefix &*^%!~ {} @prefix func &*^%!~(s: String) -> String { return s.uppercaseString } operator infix ^^ { associativity left } @infix func ^^(a: Double, b: Double) -> Double { return pow(a, b) } println(&*^%!~"hello") // prints "HELLO" println(2.0^^4.0) // prints 8.0 Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 28. Swift and Objective-C Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 29. Building an iOS app with Swift DEMO Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 30. Wrapping Up • Most iOS developers are extremely excited about Swift • Swift has a much smoother learning curve and fixes many Objective-C mistakes • For the foreseeable future though, we will still use both languages Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift
  • 31. Sasha Goldshtein blog.sashag.net @goldshtn s.sashag.net/sa-swift Thank You! Join the conversation on Twitter: @SoftArchConf #SA2014 This presentation: http://s.sashag.net/sa-swift

Editor's Notes

  1. Quote source: http://blogs.msdn.com/b/ericgu/archive/2004/01/12/57985.aspx