SlideShare a Scribd company logo
Keith Moon - Senior iOS Developer
Thinking In Swift
MBLT.dev - Moscow
November 2016
2
• iOS Developer since 2010
• Worked with BBC News, Hotels.com and Travelex
• Working in Swift since it’s release
• Built 2 apps end to end in Swift
• “Swift 3 Cookbook” to be published by Pakt
Who am I?
@keefmoon
3
• Help users discover great local food
• Make it quick and easy to order from a wide variety of takeaways
• Available on:
–Web
–iOS
–Android
–Amazon Echo
What is Just Eat?
3
4
• Australia
• Brazil
• Canada
• Denmark
• France
• Ireland
• Italy
• Mexico
What is Just Eat?
Global Business
• New Zealand
• Norway
• Spain
• Switzerland
• UK
5
• 12 iOS Developers
• Organised around feature teams
• Mixture of Objective-C and Swift
• Regular releases
• Multi-Variant Testing
• Research team investigating new technology
What is Just Eat?
5
6
What is Just Eat?
• 12 iOS Developers
• Organised around feature teams
• Mixture of Objective-C and Swift
• Regular releases
• Multi-Variant Testing
• Research team investigating new technology
7
Purpose of this talk?
• Swift is fundamentally different to Objective-C
• Not just different syntax
• Swift has more “tools in the toolbox”
How do we “think in Swift”?
How do we “think in Swift”?
8
• Use constructs that more closely match the model
• Write code that is hard to use wrong
• Remove the need for trivial tests
• Consider a Protocol orientated approach
Structs
The right tool for the job
Class Objects
Enums
Protocols
+ Extensions
Constrained
Extensions
Tuples
Enums
• Integer based
• Typedef
• …and that’s it.
typedef enum : NSUInteger {
JEPaymentOptionCash,
JEPaymentOptionSavedCard,
JEPaymentOptionApplePay,
JEPaymentOptionAccountCredit
} JEPaymentOption;
- (void)payByOption:(JEPaymentOption)option {
// Pay ...
}
Enums
• Based on any RawRepresentable
enum PaymentOption: String {
case cash
case savedCard
case applePay
case accountCredit
}
Enums
• Based on any RawRepresentable
• … or not.
enum PaymentOption {
case cash
case savedCard
case applePay
case accountCredit
}
Enums
• Based on any RawRepresentable
• … or not.
• Associated Types
enum PaymentOption {
case cash
case savedCard(SavedCard)
case applePay
case accountCredit
}
Enums
• Based on any RawRepresentable
• … or not.
• Associated Types
• Methods
enum PaymentOption {
case cash
case savedCard(SavedCard)
case applePay
case accountCredit
func canPay(at rest: Restaurant) -> Bool {
//...
}
}
Enums
• Based on any RawRepresentable
• … or not.
• Associated Types
• Methods
• Computed variables
enum PaymentOption {
case cash
case savedCard(SavedCard)
case applePay
case accountCredit
func canPay(at rest: Restaurant) -> Bool {
//...
}
var isDeviceSupported: Bool {
//...
}
}
Example App
16
Value Type Semantics
17
SearchFilter
postcode: BR13HP
cuisine: nil
S
Value Type Semantics
18
SearchFilter
postcode: BR13HP
cuisine: nil
S
SearchFilter
postcode: BR13HP
cuisine: nil
S
Value Type Semantics
19
SearchFilter
postcode: BR13HP
cuisine: nil
S
SearchFilter
postcode: BR13HP
cuisine: Chicken
S
Value Type Semantics
20
SearchFilter
postcode: BR13HP
cuisine: nil
S
Reference Type Semantics
21
SearchFilter
postcode: BR13HP
cuisine: nil
C
Reference Type Semantics
22
SearchFilter
postcode: BR13HP
cuisine: nil
C
Reference Type Semantics
23
SearchFilter
postcode: BR13HP
cuisine: Chicken
C
Reference Type Semantics
24
SearchFilter
postcode: BR13HP
cuisine: Chicken
C
enum Cuisine: Int {
case american
case bangladeshi
//...
case thai
case turkish
init?(string: String) {
guard let index = Cuisine.stringValues.index(of: string),
let cuisine = Cuisine(rawValue: index) else {
return nil
}
self = cuisine
}
var displayString: String {
return Cuisine.stringValues[rawValue]
}
private static var stringValues: [String] {
return ["American",
"Bangladeshi",
//...
"Thai",
"Turkish"]
}
}
25
enum Cuisine: Int, CaseCountable {
case american
case bangladeshi
//...
case thai
case turkish
init?(string: String) {
for index in 0..<Cuisine.caseCount {
if let cuisine = Cuisine(rawValue: index),
cuisine.displayString == string {
self = cuisine
return
}
}
return nil
}
var displayString: String {
return String(describing: self).capitalized
}
}
Cuisine Enum -
NewOld
restaurantService.fetchRestaurants(for: postcode) { [weak self] (fetchedRestaurants, error) in
if let fetchedRestaurants = fetchedRestaurants {
self?.allRestaurants = fetchedRestaurants
self?.visibleRestaurants = fetchedRestaurants
self?.tableView.reloadData()
} else if let error = error {
// Handle Error
print(error)
}
}
26
enum RestaurantResult {
case success([Restaurant])
case failure(Error)
}
restaurantService.fetchRestaurants(for: postcode) { [weak self] result
in
switch result {
case .success(let fetchedRestaurants):
self?.allRestaurants = fetchedRestaurants
self?.visibleRestaurants = fetchedRestaurants
self?.tableView.reloadData()
case .failure(let error):
// Handle Error
print(error)
}
}
Networking Result -
New
Old
Reference Type Semantics
27
Margherita Pizza
C
Vegetarian Pizza
C
Coca-Cola
C
Sprite
C
Reference Type Semantics
28
Margherita Pizza
C
Vegetarian Pizza
C
Coca-Cola
C
Sprite
C
Reference Type Semantics
29
Margherita Pizza
C
Vegetarian Pizza
C
Coca-Cola
C
Sprite
C
Value Type Semantics
30
Margherita Pizza
S
Vegetarian Pizza
S
Vegetarian Pizza
S
Coca-Cola
S
Coca-Cola
S
Sprite
S
Value Type Semantics
31
Margherita Pizza
S
Vegetarian Pizza
S
Vegetarian Pizza
S
Coca-Cola
S
Coca-Cola
S
Sprite
S
Value Type Semantics
32
Margherita Pizza
S
Vegetarian Pizza
S
Vegetarian Pizza
S
Coca-Cola
S
Coca-Cola
S
Sprite
S
Summary
● Pick the appropriate Swift type for the concept being modelled
● Consider the Type semantics
● Defining behaviours as protocols can produce expressive code
● Avoid “Stringly” typed implementations
● Try to anticipate and prevent future developer errors
33
Thanks! @keefmoon
keith.moon@just-eat.com
keefmoon

More Related Content

Viewers also liked

Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
Jonathan Engelsma
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
Jonathan Engelsma
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
Mindfire Solutions
 
Modern Objective-C @ Pragma Night
Modern Objective-C @ Pragma NightModern Objective-C @ Pragma Night
Modern Objective-C @ Pragma Night
Giuseppe Arici
 
Ios - Intorduction to view controller
Ios - Intorduction to view controllerIos - Intorduction to view controller
Ios - Intorduction to view controller
Vibrant Technologies & Computers
 
iOS: Table Views
iOS: Table ViewsiOS: Table Views
iOS: Table Views
Jussi Pohjolainen
 
Spring MVC to iOS and the REST
Spring MVC to iOS and the RESTSpring MVC to iOS and the REST
Spring MVC to iOS and the REST
Roy Clarkson
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Jinkyu Kim
 
Workshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - StructuresWorkshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - Structures
Visual Engineering
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
Giordano Scalzo
 
Apple iOS
Apple iOSApple iOS
Apple iOS
Chetan Gowda
 
An Introduction into the design of business using business architecture
An Introduction into the design of business using business architectureAn Introduction into the design of business using business architecture
An Introduction into the design of business using business architecture
Craig Martin
 
Writing Your App Swiftly
Writing Your App SwiftlyWriting Your App Swiftly
Writing Your App Swiftly
Sommer Panage
 

Viewers also liked (15)

Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Modern Objective-C @ Pragma Night
Modern Objective-C @ Pragma NightModern Objective-C @ Pragma Night
Modern Objective-C @ Pragma Night
 
Ios - Intorduction to view controller
Ios - Intorduction to view controllerIos - Intorduction to view controller
Ios - Intorduction to view controller
 
iOS: Table Views
iOS: Table ViewsiOS: Table Views
iOS: Table Views
 
Spring MVC to iOS and the REST
Spring MVC to iOS and the RESTSpring MVC to iOS and the REST
Spring MVC to iOS and the REST
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
Workshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - StructuresWorkshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - Structures
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 
An Introduction into the design of business using business architecture
An Introduction into the design of business using business architectureAn Introduction into the design of business using business architecture
An Introduction into the design of business using business architecture
 
Writing Your App Swiftly
Writing Your App SwiftlyWriting Your App Swiftly
Writing Your App Swiftly
 

Similar to Thinking in swift ppt

Diversified application testing based on a Sylius project
Diversified application testing based on a Sylius projectDiversified application testing based on a Sylius project
Diversified application testing based on a Sylius project
Łukasz Chruściel
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
Andrzej Sitek
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
Michelangelo van Dam
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into Swift
Sarath C
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
Steve Upton
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
Jeroen Rosenberg
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
Kerry Buckley
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
Ortus Solutions, Corp
 
Tips for Building your First XPages Java Application
Tips for Building your First XPages Java ApplicationTips for Building your First XPages Java Application
Tips for Building your First XPages Java Application
Teamstudio
 
Swift meetup22june2015
Swift meetup22june2015Swift meetup22june2015
Swift meetup22june2015
Claire Townend Gee
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
Andrey Karpov
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
Droidcon Berlin
 
API first with Swagger and Scala by Slava Schmidt
API first with Swagger and Scala by  Slava SchmidtAPI first with Swagger and Scala by  Slava Schmidt
API first with Swagger and Scala by Slava Schmidt
JavaDayUA
 
High ROI Testing in Angular.pptx
High ROI Testing in Angular.pptxHigh ROI Testing in Angular.pptx
High ROI Testing in Angular.pptx
Christian Lüdemann
 
Testing the waters of iOS
Testing the waters of iOSTesting the waters of iOS
Testing the waters of iOS
Kremizas Kostas
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
Azilen Technologies Pvt. Ltd.
 
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
it-people
 

Similar to Thinking in swift ppt (20)

Diversified application testing based on a Sylius project
Diversified application testing based on a Sylius projectDiversified application testing based on a Sylius project
Diversified application testing based on a Sylius project
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into Swift
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
Tips for Building your First XPages Java Application
Tips for Building your First XPages Java ApplicationTips for Building your First XPages Java Application
Tips for Building your First XPages Java Application
 
Swift meetup22june2015
Swift meetup22june2015Swift meetup22june2015
Swift meetup22june2015
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
 
API first with Swagger and Scala by Slava Schmidt
API first with Swagger and Scala by  Slava SchmidtAPI first with Swagger and Scala by  Slava Schmidt
API first with Swagger and Scala by Slava Schmidt
 
High ROI Testing in Angular.pptx
High ROI Testing in Angular.pptxHigh ROI Testing in Angular.pptx
High ROI Testing in Angular.pptx
 
Testing the waters of iOS
Testing the waters of iOSTesting the waters of iOS
Testing the waters of iOS
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
 

Recently uploaded

How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
AnkitaPandya11
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 

Recently uploaded (20)

How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 

Thinking in swift ppt

  • 1. Keith Moon - Senior iOS Developer Thinking In Swift MBLT.dev - Moscow November 2016
  • 2. 2 • iOS Developer since 2010 • Worked with BBC News, Hotels.com and Travelex • Working in Swift since it’s release • Built 2 apps end to end in Swift • “Swift 3 Cookbook” to be published by Pakt Who am I? @keefmoon
  • 3. 3 • Help users discover great local food • Make it quick and easy to order from a wide variety of takeaways • Available on: –Web –iOS –Android –Amazon Echo What is Just Eat? 3
  • 4. 4 • Australia • Brazil • Canada • Denmark • France • Ireland • Italy • Mexico What is Just Eat? Global Business • New Zealand • Norway • Spain • Switzerland • UK
  • 5. 5 • 12 iOS Developers • Organised around feature teams • Mixture of Objective-C and Swift • Regular releases • Multi-Variant Testing • Research team investigating new technology What is Just Eat? 5
  • 6. 6 What is Just Eat? • 12 iOS Developers • Organised around feature teams • Mixture of Objective-C and Swift • Regular releases • Multi-Variant Testing • Research team investigating new technology
  • 7. 7 Purpose of this talk? • Swift is fundamentally different to Objective-C • Not just different syntax • Swift has more “tools in the toolbox” How do we “think in Swift”?
  • 8. How do we “think in Swift”? 8 • Use constructs that more closely match the model • Write code that is hard to use wrong • Remove the need for trivial tests • Consider a Protocol orientated approach
  • 9. Structs The right tool for the job Class Objects Enums Protocols + Extensions Constrained Extensions Tuples
  • 10. Enums • Integer based • Typedef • …and that’s it. typedef enum : NSUInteger { JEPaymentOptionCash, JEPaymentOptionSavedCard, JEPaymentOptionApplePay, JEPaymentOptionAccountCredit } JEPaymentOption; - (void)payByOption:(JEPaymentOption)option { // Pay ... }
  • 11. Enums • Based on any RawRepresentable enum PaymentOption: String { case cash case savedCard case applePay case accountCredit }
  • 12. Enums • Based on any RawRepresentable • … or not. enum PaymentOption { case cash case savedCard case applePay case accountCredit }
  • 13. Enums • Based on any RawRepresentable • … or not. • Associated Types enum PaymentOption { case cash case savedCard(SavedCard) case applePay case accountCredit }
  • 14. Enums • Based on any RawRepresentable • … or not. • Associated Types • Methods enum PaymentOption { case cash case savedCard(SavedCard) case applePay case accountCredit func canPay(at rest: Restaurant) -> Bool { //... } }
  • 15. Enums • Based on any RawRepresentable • … or not. • Associated Types • Methods • Computed variables enum PaymentOption { case cash case savedCard(SavedCard) case applePay case accountCredit func canPay(at rest: Restaurant) -> Bool { //... } var isDeviceSupported: Bool { //... } }
  • 18. Value Type Semantics 18 SearchFilter postcode: BR13HP cuisine: nil S SearchFilter postcode: BR13HP cuisine: nil S
  • 19. Value Type Semantics 19 SearchFilter postcode: BR13HP cuisine: nil S SearchFilter postcode: BR13HP cuisine: Chicken S
  • 25. enum Cuisine: Int { case american case bangladeshi //... case thai case turkish init?(string: String) { guard let index = Cuisine.stringValues.index(of: string), let cuisine = Cuisine(rawValue: index) else { return nil } self = cuisine } var displayString: String { return Cuisine.stringValues[rawValue] } private static var stringValues: [String] { return ["American", "Bangladeshi", //... "Thai", "Turkish"] } } 25 enum Cuisine: Int, CaseCountable { case american case bangladeshi //... case thai case turkish init?(string: String) { for index in 0..<Cuisine.caseCount { if let cuisine = Cuisine(rawValue: index), cuisine.displayString == string { self = cuisine return } } return nil } var displayString: String { return String(describing: self).capitalized } } Cuisine Enum - NewOld
  • 26. restaurantService.fetchRestaurants(for: postcode) { [weak self] (fetchedRestaurants, error) in if let fetchedRestaurants = fetchedRestaurants { self?.allRestaurants = fetchedRestaurants self?.visibleRestaurants = fetchedRestaurants self?.tableView.reloadData() } else if let error = error { // Handle Error print(error) } } 26 enum RestaurantResult { case success([Restaurant]) case failure(Error) } restaurantService.fetchRestaurants(for: postcode) { [weak self] result in switch result { case .success(let fetchedRestaurants): self?.allRestaurants = fetchedRestaurants self?.visibleRestaurants = fetchedRestaurants self?.tableView.reloadData() case .failure(let error): // Handle Error print(error) } } Networking Result - New Old
  • 27. Reference Type Semantics 27 Margherita Pizza C Vegetarian Pizza C Coca-Cola C Sprite C
  • 28. Reference Type Semantics 28 Margherita Pizza C Vegetarian Pizza C Coca-Cola C Sprite C
  • 29. Reference Type Semantics 29 Margherita Pizza C Vegetarian Pizza C Coca-Cola C Sprite C
  • 30. Value Type Semantics 30 Margherita Pizza S Vegetarian Pizza S Vegetarian Pizza S Coca-Cola S Coca-Cola S Sprite S
  • 31. Value Type Semantics 31 Margherita Pizza S Vegetarian Pizza S Vegetarian Pizza S Coca-Cola S Coca-Cola S Sprite S
  • 32. Value Type Semantics 32 Margherita Pizza S Vegetarian Pizza S Vegetarian Pizza S Coca-Cola S Coca-Cola S Sprite S
  • 33. Summary ● Pick the appropriate Swift type for the concept being modelled ● Consider the Type semantics ● Defining behaviours as protocols can produce expressive code ● Avoid “Stringly” typed implementations ● Try to anticipate and prevent future developer errors 33