SlideShare a Scribd company logo
1 of 34
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

Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex
 

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

Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
Andrzej Sitek
 
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
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
Droidcon Berlin
 
«Как сделать так, чтобы тесты на 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

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 

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