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
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 {
//...
}
}
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