SlideShare a Scribd company logo
Ash Furrow, Artsy
Lessons
from
Production Swift
February, 2014
Swift
Let’s talk about
1. The Need for Swift
2. The Fast and the Faulty
3. Seek Out Bold New Worlds
Need
Swift
The
for
Objective-C
TXS ;push return address back onto stack
LDY #$00 ;load Y with zero - will hold result
LOOP1 LDAA TEMP ;load A into TEMP
ANDA MASK ;AND A with Mask
BNE ADD1
BRA NONE1
ADD1 INY ;increment our counter of 1's
NONE1 LDAA TEMP ;reload accumulator A
LSL MASK ;Shift the mask's 1 bit left
BNE LOOP1 ;If we haven't finished our loop, branch
LDAA #$01 ;load new mask into A
STAA MASK ;store the reset mask into MASK
TSX ;pull of return address and store in X
PULA ;pull off A
STAA TEMP ;store the value into temp
TXS ;push return address back onto the stack
LOOP2 LDAA TEMP ;Load A into TEMP
ANDA MASK ;logical AND MASK with A
BNE ADD2 ;add one if we need to
BRA NONE2
ADD2 INY ;increment our counter of 1's
NONE2 LDAA TEMP
LSL MASK ;shift our mask left by one
BNE LOOP2 ;loop back until we've exhausted positions
STY TEMP ;store Y into TEMP - this is the number of 1's
LDAB TEMP ;load the number of 1's into B
LDAA #$10 ;load dec 16 into A
SBA ;A - B -> A same as 16 - B -> A
—John Siracusa
“While hardware performance increases over time,
the human capacity to deal with complexity does not.”
Stuck
Objective-C
Past
is
in the
Beyond Hope
Objective-C
is
Criteria
1. No C baggage
2. Memory Managed
3. Native unicode strings
4. Native collections
5. Be concise
6. Named Parameters
Criteria
1. No C baggage
2. Memory Managed
3. Native unicode strings
4. Native collections
5. Be concise
6. Named Parameters
😋
😅
😃
😄
😍
😎
The Need for Swift
• Programming abstraction increases over time
• Objective-C has improved all it can
• Swift is the next step
• Revolution, not evolution
Fast
Faulty
The
and the
Problems In Beta
• Xcode crashes
• Compiler segfaults
• Constant changes to Swift
• Many language limitations
Problems Now
• Still some stability issues
• Still frequent changes to Swift
• Still some remaining language limitations
Problems Now
• Language changes tied to Xcode versions
• Runtime changes tied to Xcode versions
• Changes in resource-loading in frameworks
Community Tools
• Most still in their infancy
• CocoaPods, Jazzy, SBConstants…
• The rest do not exist
• Test coverage analyzer
Community Libraries
• Struggling to accomodate frequent Swift changes
• Xcode updates make this difficult
The Fast and the Faulty
• Swift had a rough start
• Was to be expected
• Things are better now
• Mostly
• Growing pains
Seek Out
New Worlds
Bold
Problem Solving in Objective-C
Problem Solving in Swift
is not
Examples
Index Paths
• Used to identify cells in a table view
• Section, row
• Lots of horrendous code
• It’s so bad
• Seriously bad
Index Paths
if (indexPath.section == 0) {
if (indexPath.row == 0) {
} else if (indexPath.row == 1) {


} else if ...
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
} else if (indexPath.row == 1) {


} else if ...
} else if ...
Index Paths
if (indexPath.section == 0) {
if (indexPath.row == 0) {
} else if (indexPath.row == 1) {


} else if ...
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
} else if (indexPath.row == 1) {


} else if ...
} else if ...
Index Paths
switch (indexPath.section, indexPath.row) {
case (0, 0):
case (0, 1):
case (1, 0):
case (1, 1):
default:
// nop
}
Still Terrible
This is
Index Paths
switch (indexPath.section, indexPath.row) {
case (0, let row):
// Executed for any section 0, row is row
case (let section, 0) where section % 2 == 1:
// Executed for first rows of odd all sections
case (let section, let row) where validate(section):
// Executed when validate() returns true
default:
// Executed on all other cases
}
Generics
• Define functions, structs, others in the abstract
• Create one instead of many
• Arrays, dictionaries, and sets are all generics
Generics
struct Stack<T> {
private var contents = Array<T>()
mutating func push(value: T) {
contents.insert(value, atIndex: 0)
}
mutating func pop() -> T {
return contents.removeAtIndex(0)
}
var isEmpty: Bool {
return countElements(contents) == 0
}
}
Generics
var intStack = Stack<Int>()
var stringStack = Stack<String>()
var stackStack = Stack<Stack<AnyObject>>()
intStack.push(1)
intStack.pop() // Returns 1
Lazy Loading
• Create resource when it is first accessed
• Avoids unnecessary work for CPU
• Avoids unnecessary memory use
Lazy Objective-C
• No language-level support
• Lots of repetition
• Tedious work
• Lots of repetition
Lazy Objective-C
@interface MyClass: NSObject
@property (nonatomic, strong) Name *name;
@end
@implementation
- (Resource *)resource {
if (_resource == nil) {
_resource = "Ash Furrow";
}
return _resource
}
@end
Lazy Swift
class MyClass {
lazy var name = "Ash Furrow"
}
Lazy Swift
class MyClass {
lazy var name = "Ash Furrow"
}
MyClass().name // Returns "Ash Furrow"
let instance = MyClass()
instance.name = "Orta Therox"
instance.name // Returns “Orta Therox"
Lazy Swift
class MyClass {
lazy var name = "Ash Furrow”
lazy var greeting: String = {
return "Hello, (self.name)"
}()
}
MyClass().greeting // Returns "Hello, Ash Furrow"
let instance = MyClass()
instance.name = "Orta Therox"
instance.greeting // Returns "Hello, Orta Therox"
instance.name = "Eloy Durán"
instance.greeting // Returns "Hello, Orta Therox"
Extending Types
• Objective-C has “categories” for extending
existing classes
• Swift has “extensions” instead
• They work on all types
Extending Types
extension Int {
func times(closure: () -> ()) {
for i in 0..<self {
closure()
}
}
}
4.times {
// Do something 4 times
}
Extending Types
extension Int {
var hours: NSTimeInterval {
return NSTimeInterval(3600 * self)
}
}
extension NSTimeInterval {
var fromNow: NSDate {
return NSDate(timeIntervalSinceNow: self)
}
var ago: NSDate {
NSDate(timeIntervalSinceNow: -self)
}
}
4.hours.fromNow
4.hours.ago
Functional Awesomeness
let people = ["Carter", "Sebastian", "Daniel"]
people.map { "Hello, ($0)!" }
func hello(name: String) -> String {
return "Hello, (name)!"
}
people.map(hello)
or…
Functional Awesomeness
func say(greeting: String) -> (name: String) -> String {
return { (name: String) -> String in
"(greeting), (name)!"
}
}
people.map(say("Hello"))
people.map(say("Merhaba"))
Functional Awesomeness
func say(greeting: String)(name: String) -> String {
return "(greeting), (name)!"
}
people.map(say("Hello"))
people.map(say("Merhaba"))
SBConstants
• Generate constants for Storyboard identifiers
• Compile-time checked enum
• Can be extended…
SBConstants
func performSegue(identifier: SegueIdentifier) {
performSegueWithIdentifier(identifier.rawValue, sender: self)
}
...
func ==(lhs: UIStoryboardSegue, rhs: SegueIdentifier) -> Bool {
return lhs.identifier == rhs.rawValue
}
SBConstants
peformSegue(.RegisterCreditCard)
...
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue == .RegisterCreditCard {
...
}
}
SBConstants
• Don’t use rawValue all over the place
• Abstract it away
• Get compile-time safety
Familiar Problems
New Ways
to solve
Let’s look for
For Advice
Ask
other communities
Let’s
Resources
• Natasha the Robot’s newsletter
• iOSDevWeekly
• iOS Goodies
• GitHub Explore
• leanpub.com/yourfirstswiftapp
Eidolon
1. The Need for Swift
2. The Fast and the Faulty
3. Seek Out Bold New Worlds
Better Mistakes
Make
Tomorrow

More Related Content

What's hot

Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
pramode_ce
 

What's hot (20)

Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Introduction to Scala : Clueda
Introduction to Scala : CluedaIntroduction to Scala : Clueda
Introduction to Scala : Clueda
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDD
 
All about scala
All about scalaAll about scala
All about scala
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Scala on Android
Scala on AndroidScala on Android
Scala on Android
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
scala
scalascala
scala
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 

Similar to ITT 2015 - Ash Furrow - Lessons from Production Swift

Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
chenge2k
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
Scala Italy
 

Similar to ITT 2015 - Ash Furrow - Lessons from Production Swift (20)

Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala Makeover
 
Lua Study Share
Lua Study ShareLua Study Share
Lua Study Share
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About Scala
 
Scala in Practice
Scala in PracticeScala in Practice
Scala in Practice
 
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
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad PečanacJavantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 

More from Istanbul Tech Talks

More from Istanbul Tech Talks (15)

ITT 2015 - Kirk Pepperdine - The (not so) Dark Art of Performance Tuning, fro...
ITT 2015 - Kirk Pepperdine - The (not so) Dark Art of Performance Tuning, fro...ITT 2015 - Kirk Pepperdine - The (not so) Dark Art of Performance Tuning, fro...
ITT 2015 - Kirk Pepperdine - The (not so) Dark Art of Performance Tuning, fro...
 
ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and ScaleITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
 
ITT 2015 - Vincent Garrigues - Continuous Integration at SoundCloud
ITT 2015 - Vincent Garrigues - Continuous Integration at SoundCloudITT 2015 - Vincent Garrigues - Continuous Integration at SoundCloud
ITT 2015 - Vincent Garrigues - Continuous Integration at SoundCloud
 
ITT 2015 - Simon Tennant - Your App Just Got Social: Adding Messaging to Your...
ITT 2015 - Simon Tennant - Your App Just Got Social: Adding Messaging to Your...ITT 2015 - Simon Tennant - Your App Just Got Social: Adding Messaging to Your...
ITT 2015 - Simon Tennant - Your App Just Got Social: Adding Messaging to Your...
 
ITT 2015 - Hugo Domenech-Juarez - What's All That Hype About BLE?
ITT 2015 - Hugo Domenech-Juarez - What's All That Hype About BLE?ITT 2015 - Hugo Domenech-Juarez - What's All That Hype About BLE?
ITT 2015 - Hugo Domenech-Juarez - What's All That Hype About BLE?
 
ITT 2014 - Mario Zechner - Libgdx 101
ITT 2014 - Mario Zechner - Libgdx 101ITT 2014 - Mario Zechner - Libgdx 101
ITT 2014 - Mario Zechner - Libgdx 101
 
ITT 2014 - Orta Therox- Mobile and the Art World
ITT 2014 - Orta Therox- Mobile and the Art WorldITT 2014 - Orta Therox- Mobile and the Art World
ITT 2014 - Orta Therox- Mobile and the Art World
 
ITT 2014 - Niklas Therning - Truly Native Java Apps on iOS with RoboVM
ITT 2014 - Niklas Therning - Truly Native Java Apps on iOS with RoboVMITT 2014 - Niklas Therning - Truly Native Java Apps on iOS with RoboVM
ITT 2014 - Niklas Therning - Truly Native Java Apps on iOS with RoboVM
 
ITT 2014 - Peter Steinberger - Architecting Modular Codebases
ITT 2014 - Peter Steinberger - Architecting Modular CodebasesITT 2014 - Peter Steinberger - Architecting Modular Codebases
ITT 2014 - Peter Steinberger - Architecting Modular Codebases
 
ITT 2014 - Max Seelemann - Hello TextKit!
ITT 2014 - Max Seelemann - Hello TextKit!ITT 2014 - Max Seelemann - Hello TextKit!
ITT 2014 - Max Seelemann - Hello TextKit!
 
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
 
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better NetworkingITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
 
ITT 2014 - Chris Eidhof - Practical Concurrent Programming
ITT 2014 - Chris Eidhof - Practical Concurrent ProgrammingITT 2014 - Chris Eidhof - Practical Concurrent Programming
ITT 2014 - Chris Eidhof - Practical Concurrent Programming
 
ITT 2014 - Matt Brenner- Localization 2.0
ITT 2014 - Matt Brenner- Localization 2.0ITT 2014 - Matt Brenner- Localization 2.0
ITT 2014 - Matt Brenner- Localization 2.0
 

Recently uploaded

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
Atif Razi
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 

Recently uploaded (20)

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 

ITT 2015 - Ash Furrow - Lessons from Production Swift

  • 4. 1. The Need for Swift 2. The Fast and the Faulty 3. Seek Out Bold New Worlds
  • 7. TXS ;push return address back onto stack LDY #$00 ;load Y with zero - will hold result LOOP1 LDAA TEMP ;load A into TEMP ANDA MASK ;AND A with Mask BNE ADD1 BRA NONE1 ADD1 INY ;increment our counter of 1's NONE1 LDAA TEMP ;reload accumulator A LSL MASK ;Shift the mask's 1 bit left BNE LOOP1 ;If we haven't finished our loop, branch LDAA #$01 ;load new mask into A STAA MASK ;store the reset mask into MASK TSX ;pull of return address and store in X PULA ;pull off A STAA TEMP ;store the value into temp TXS ;push return address back onto the stack LOOP2 LDAA TEMP ;Load A into TEMP ANDA MASK ;logical AND MASK with A BNE ADD2 ;add one if we need to BRA NONE2 ADD2 INY ;increment our counter of 1's NONE2 LDAA TEMP LSL MASK ;shift our mask left by one BNE LOOP2 ;loop back until we've exhausted positions STY TEMP ;store Y into TEMP - this is the number of 1's LDAB TEMP ;load the number of 1's into B LDAA #$10 ;load dec 16 into A SBA ;A - B -> A same as 16 - B -> A
  • 8. —John Siracusa “While hardware performance increases over time, the human capacity to deal with complexity does not.”
  • 11. Criteria 1. No C baggage 2. Memory Managed 3. Native unicode strings 4. Native collections 5. Be concise 6. Named Parameters
  • 12. Criteria 1. No C baggage 2. Memory Managed 3. Native unicode strings 4. Native collections 5. Be concise 6. Named Parameters 😋 😅 😃 😄 😍 😎
  • 13. The Need for Swift • Programming abstraction increases over time • Objective-C has improved all it can • Swift is the next step • Revolution, not evolution
  • 15. Problems In Beta • Xcode crashes • Compiler segfaults • Constant changes to Swift • Many language limitations
  • 16. Problems Now • Still some stability issues • Still frequent changes to Swift • Still some remaining language limitations
  • 17. Problems Now • Language changes tied to Xcode versions • Runtime changes tied to Xcode versions • Changes in resource-loading in frameworks
  • 18. Community Tools • Most still in their infancy • CocoaPods, Jazzy, SBConstants… • The rest do not exist • Test coverage analyzer
  • 19. Community Libraries • Struggling to accomodate frequent Swift changes • Xcode updates make this difficult
  • 20. The Fast and the Faulty • Swift had a rough start • Was to be expected • Things are better now • Mostly • Growing pains
  • 22. Problem Solving in Objective-C Problem Solving in Swift is not
  • 24. Index Paths • Used to identify cells in a table view • Section, row • Lots of horrendous code • It’s so bad • Seriously bad
  • 25. Index Paths if (indexPath.section == 0) { if (indexPath.row == 0) { } else if (indexPath.row == 1) { 
 } else if ... } else if (indexPath.section == 1) { if (indexPath.row == 0) { } else if (indexPath.row == 1) { 
 } else if ... } else if ...
  • 26. Index Paths if (indexPath.section == 0) { if (indexPath.row == 0) { } else if (indexPath.row == 1) { 
 } else if ... } else if (indexPath.section == 1) { if (indexPath.row == 0) { } else if (indexPath.row == 1) { 
 } else if ... } else if ...
  • 27. Index Paths switch (indexPath.section, indexPath.row) { case (0, 0): case (0, 1): case (1, 0): case (1, 1): default: // nop }
  • 29. Index Paths switch (indexPath.section, indexPath.row) { case (0, let row): // Executed for any section 0, row is row case (let section, 0) where section % 2 == 1: // Executed for first rows of odd all sections case (let section, let row) where validate(section): // Executed when validate() returns true default: // Executed on all other cases }
  • 30. Generics • Define functions, structs, others in the abstract • Create one instead of many • Arrays, dictionaries, and sets are all generics
  • 31. Generics struct Stack<T> { private var contents = Array<T>() mutating func push(value: T) { contents.insert(value, atIndex: 0) } mutating func pop() -> T { return contents.removeAtIndex(0) } var isEmpty: Bool { return countElements(contents) == 0 } }
  • 32. Generics var intStack = Stack<Int>() var stringStack = Stack<String>() var stackStack = Stack<Stack<AnyObject>>() intStack.push(1) intStack.pop() // Returns 1
  • 33. Lazy Loading • Create resource when it is first accessed • Avoids unnecessary work for CPU • Avoids unnecessary memory use
  • 34. Lazy Objective-C • No language-level support • Lots of repetition • Tedious work • Lots of repetition
  • 35. Lazy Objective-C @interface MyClass: NSObject @property (nonatomic, strong) Name *name; @end @implementation - (Resource *)resource { if (_resource == nil) { _resource = "Ash Furrow"; } return _resource } @end
  • 36. Lazy Swift class MyClass { lazy var name = "Ash Furrow" }
  • 37. Lazy Swift class MyClass { lazy var name = "Ash Furrow" } MyClass().name // Returns "Ash Furrow" let instance = MyClass() instance.name = "Orta Therox" instance.name // Returns “Orta Therox"
  • 38. Lazy Swift class MyClass { lazy var name = "Ash Furrow” lazy var greeting: String = { return "Hello, (self.name)" }() } MyClass().greeting // Returns "Hello, Ash Furrow" let instance = MyClass() instance.name = "Orta Therox" instance.greeting // Returns "Hello, Orta Therox" instance.name = "Eloy Durán" instance.greeting // Returns "Hello, Orta Therox"
  • 39. Extending Types • Objective-C has “categories” for extending existing classes • Swift has “extensions” instead • They work on all types
  • 40. Extending Types extension Int { func times(closure: () -> ()) { for i in 0..<self { closure() } } } 4.times { // Do something 4 times }
  • 41. Extending Types extension Int { var hours: NSTimeInterval { return NSTimeInterval(3600 * self) } } extension NSTimeInterval { var fromNow: NSDate { return NSDate(timeIntervalSinceNow: self) } var ago: NSDate { NSDate(timeIntervalSinceNow: -self) } } 4.hours.fromNow 4.hours.ago
  • 42. Functional Awesomeness let people = ["Carter", "Sebastian", "Daniel"] people.map { "Hello, ($0)!" } func hello(name: String) -> String { return "Hello, (name)!" } people.map(hello) or…
  • 43. Functional Awesomeness func say(greeting: String) -> (name: String) -> String { return { (name: String) -> String in "(greeting), (name)!" } } people.map(say("Hello")) people.map(say("Merhaba"))
  • 44. Functional Awesomeness func say(greeting: String)(name: String) -> String { return "(greeting), (name)!" } people.map(say("Hello")) people.map(say("Merhaba"))
  • 45. SBConstants • Generate constants for Storyboard identifiers • Compile-time checked enum • Can be extended…
  • 46. SBConstants func performSegue(identifier: SegueIdentifier) { performSegueWithIdentifier(identifier.rawValue, sender: self) } ... func ==(lhs: UIStoryboardSegue, rhs: SegueIdentifier) -> Bool { return lhs.identifier == rhs.rawValue }
  • 47. SBConstants peformSegue(.RegisterCreditCard) ... func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue == .RegisterCreditCard { ... } }
  • 48. SBConstants • Don’t use rawValue all over the place • Abstract it away • Get compile-time safety
  • 49. Familiar Problems New Ways to solve Let’s look for
  • 51. Resources • Natasha the Robot’s newsletter • iOSDevWeekly • iOS Goodies • GitHub Explore • leanpub.com/yourfirstswiftapp
  • 53. 1. The Need for Swift 2. The Fast and the Faulty 3. Seek Out Bold New Worlds