SlideShare a Scribd company logo
1 of 20
Download to read offline
SWIFT 2 INTRODUCTION
SWIFT
Powerful new language created by Apple
Works side by side with Objective-C
Syntax is closer to popular languages
VAR VS LET
var for regular variables
let for constants
camelCase your variable names
var variableNumber = 5
let constantNumber = 3.14
TYPE INFERENCE
Swift is strongly typed
The type will be inferred when not specified
var explicitVariable: Int = 10
var inferredVariable = 10
var explicitVariable2: Double = 10
OPTIONALS
Regular types must always have a value
Optional types used when value may be nil
Denote optionals with a ?
var alwaysAnInt: Int = 15
var maybeAnInt: Int? = 15
maybeAnInt = nil
UNWRAPPING AN OPTIONAL
Optionals must be unwrapped before using
Can be checked for nil with an if-statement
Once checked, force unwrap optionals with !
if maybeAnInt != nil {
print("maybeAnInt contains (maybeAnInt!)")
}
OPTIONAL BINDING
Cleaner way to unwrap optionals
"Binds" value of optional to new variable
if let definitelyAnInt = maybeAnInt {
print("maybeAnInt contains (definitelyAnInt)")
}
IMPLICITLY UNWRAPPED
OPTIONALS
Trigger a runtime error when accessed if
the value is nil
Denoted using a !
var alwaysAString: String! = nil
let stringLength = alwaysAString.characters.count
OPTIONAL CHAINING
Cannot access optional without unwrapping
Chaining only accesses if value not nil
var optionalArray: [Int]? = [ 1, 2, 3, 4 ]
var arrayLength = optionalArray?.count
ARRAYS
Can only contain a single type
Immutable arrays use let, mutable use var
count, isEmpty, append, insert
let groceryList: [String] = ["eggs", "milk"]
var mutableGroceryList = ["eggs", "milk"]
var item = mutableGroceryList[0]
DICTIONARIES
Hold key-value pairs
Keys and values each can only be one type
Best to use optional binding when accessing
var cities = ["New York City" : "USA", "London" : "UK"]
cities["London"]
cities["London"] = nil
CLASSES VS STRUCTS
class PersonRefType {
let name:String
var age:Int
// ..
}
// 1
let peter = PersonRefType(name: "Peter", age: 36)
// 2
let peter2 = peter
// 3
peter2.age = 25
// peter {"Peter", 25}
// peter2 {"Peter", 25}
CLASSES VS STRUCTS
struct Person {
let name:String
var age:Int
}
// 1
let petra = Person(name:"Petra", age:25)
// 2
var petra2 = petra
// 3
petra2.age = 20
// petra {"Petra", 25}
// petra2 {"Petra", 20}
NEW IN SWIFT 2
ERROR HANDLING
Functions and methods can throw
Calling functions need to handle errors
ERROR HANDLING
enum TripError: ErrorType {
case NoWaypointsProvided
}
func createTrip() throws {
throw TripError.NoWaypointsProvided
}
func buttonTapped() {
do {
try createTrip()
} catch TripError.NoWaypointsProvided {
print("oh-oh")
} catch {
print("other error")
}
}
GUARD
Alternative to optional binding
func printRating() {
guard let customerRating = rating?.customerRating,
merchantRating = rating?.merchantRating,
ratingDate = rating?.ratingDate else { return }
print("Customer: (customerRating), Merchant: (merchantRating), Rating Date: (ratingDate)")
}
PROTOCOL EXTENSIONS
Provide implementation as part of protocol
protocol Vehicle {
var speed: Double { get set }
func travelDuration(distance: Double) -> Double
}
extension Vehicle {
func travelDuration(distance: Double) -> Double {
return distance / speed
}
}
Swift 2 intro

More Related Content

Viewers also liked

Make School 2017 - Mastering iOS Development
Make School 2017 - Mastering iOS DevelopmentMake School 2017 - Mastering iOS Development
Make School 2017 - Mastering iOS DevelopmentMake School
 
Error Handling in Swift
Error Handling in SwiftError Handling in Swift
Error Handling in SwiftMake School
 
Layout with Stack View, Table View, and Collection View
Layout with Stack View, Table View, and Collection ViewLayout with Stack View, Table View, and Collection View
Layout with Stack View, Table View, and Collection ViewMake School
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOSMake School
 
Intro to iOS Application Architecture
Intro to iOS Application ArchitectureIntro to iOS Application Architecture
Intro to iOS Application ArchitectureMake School
 
Memory Management on iOS
Memory Management on iOSMemory Management on iOS
Memory Management on iOSMake School
 
Distributing information on iOS
Distributing information on iOSDistributing information on iOS
Distributing information on iOSMake School
 
Advanced Core Data
Advanced Core DataAdvanced Core Data
Advanced Core DataMake School
 
Persistence on iOS
Persistence on iOSPersistence on iOS
Persistence on iOSMake School
 
iOS Layout Overview
iOS Layout OverviewiOS Layout Overview
iOS Layout OverviewMake School
 
Building a Backend with Flask
Building a Backend with FlaskBuilding a Backend with Flask
Building a Backend with FlaskMake School
 
Intro to Core Data
Intro to Core DataIntro to Core Data
Intro to Core DataMake School
 
Client Server Security with Flask and iOS
Client Server Security with Flask and iOSClient Server Security with Flask and iOS
Client Server Security with Flask and iOSMake School
 
Automated Testing on iOS
Automated Testing on iOSAutomated Testing on iOS
Automated Testing on iOSMake School
 
How to build quality software
How to build quality softwareHow to build quality software
How to build quality softwareMake School
 

Viewers also liked (15)

Make School 2017 - Mastering iOS Development
Make School 2017 - Mastering iOS DevelopmentMake School 2017 - Mastering iOS Development
Make School 2017 - Mastering iOS Development
 
Error Handling in Swift
Error Handling in SwiftError Handling in Swift
Error Handling in Swift
 
Layout with Stack View, Table View, and Collection View
Layout with Stack View, Table View, and Collection ViewLayout with Stack View, Table View, and Collection View
Layout with Stack View, Table View, and Collection View
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOS
 
Intro to iOS Application Architecture
Intro to iOS Application ArchitectureIntro to iOS Application Architecture
Intro to iOS Application Architecture
 
Memory Management on iOS
Memory Management on iOSMemory Management on iOS
Memory Management on iOS
 
Distributing information on iOS
Distributing information on iOSDistributing information on iOS
Distributing information on iOS
 
Advanced Core Data
Advanced Core DataAdvanced Core Data
Advanced Core Data
 
Persistence on iOS
Persistence on iOSPersistence on iOS
Persistence on iOS
 
iOS Layout Overview
iOS Layout OverviewiOS Layout Overview
iOS Layout Overview
 
Building a Backend with Flask
Building a Backend with FlaskBuilding a Backend with Flask
Building a Backend with Flask
 
Intro to Core Data
Intro to Core DataIntro to Core Data
Intro to Core Data
 
Client Server Security with Flask and iOS
Client Server Security with Flask and iOSClient Server Security with Flask and iOS
Client Server Security with Flask and iOS
 
Automated Testing on iOS
Automated Testing on iOSAutomated Testing on iOS
Automated Testing on iOS
 
How to build quality software
How to build quality softwareHow to build quality software
How to build quality software
 

Similar to Swift 2 intro

Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Manoj Ellappan
 
42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton typesGeorge Leontiev
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...Mark Simon
 
The swift programming language
The swift programming languageThe swift programming language
The swift programming languagePardeep Chaudhary
 
Intermediate Swift Language by Apple
Intermediate Swift Language by AppleIntermediate Swift Language by Apple
Intermediate Swift Language by Applejamesfeng2
 
iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)Ahmed Ali
 
F# and Reactive Programming for iOS
F# and Reactive Programming for iOSF# and Reactive Programming for iOS
F# and Reactive Programming for iOSBrad Pillow
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsJigar Gosar
 
Complete Overview about PERL
Complete Overview about PERLComplete Overview about PERL
Complete Overview about PERLRavi kumar
 
Reason - introduction to language and its ecosystem | Łukasz Strączyński
Reason - introduction to language and its ecosystem | Łukasz StrączyńskiReason - introduction to language and its ecosystem | Łukasz Strączyński
Reason - introduction to language and its ecosystem | Łukasz StrączyńskiGrand Parade Poland
 
Introduction to scala
Introduction to scalaIntroduction to scala
Introduction to scalaMichel Perez
 

Similar to Swift 2 intro (17)

Intro toswift1
Intro toswift1Intro toswift1
Intro toswift1
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
 
Swift Basics
Swift BasicsSwift Basics
Swift Basics
 
42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton types
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
 
The swift programming language
The swift programming languageThe swift programming language
The swift programming language
 
Intermediate Swift Language by Apple
Intermediate Swift Language by AppleIntermediate Swift Language by Apple
Intermediate Swift Language by Apple
 
iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 
F# and Reactive Programming for iOS
F# and Reactive Programming for iOSF# and Reactive Programming for iOS
F# and Reactive Programming for iOS
 
Just Kotlin
Just KotlinJust Kotlin
Just Kotlin
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
 
Complete Overview about PERL
Complete Overview about PERLComplete Overview about PERL
Complete Overview about PERL
 
Basic swift
Basic swiftBasic swift
Basic swift
 
Reason - introduction to language and its ecosystem | Łukasz Strączyński
Reason - introduction to language and its ecosystem | Łukasz StrączyńskiReason - introduction to language and its ecosystem | Łukasz Strączyński
Reason - introduction to language and its ecosystem | Łukasz Strączyński
 
Introduction to scala
Introduction to scalaIntroduction to scala
Introduction to scala
 
Javascript
JavascriptJavascript
Javascript
 

Recently uploaded

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 

Recently uploaded (20)

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 

Swift 2 intro

  • 1.
  • 3. SWIFT Powerful new language created by Apple Works side by side with Objective-C Syntax is closer to popular languages
  • 4. VAR VS LET var for regular variables let for constants camelCase your variable names var variableNumber = 5 let constantNumber = 3.14
  • 5. TYPE INFERENCE Swift is strongly typed The type will be inferred when not specified var explicitVariable: Int = 10 var inferredVariable = 10 var explicitVariable2: Double = 10
  • 6. OPTIONALS Regular types must always have a value Optional types used when value may be nil Denote optionals with a ? var alwaysAnInt: Int = 15 var maybeAnInt: Int? = 15 maybeAnInt = nil
  • 7. UNWRAPPING AN OPTIONAL Optionals must be unwrapped before using Can be checked for nil with an if-statement Once checked, force unwrap optionals with ! if maybeAnInt != nil { print("maybeAnInt contains (maybeAnInt!)") }
  • 8. OPTIONAL BINDING Cleaner way to unwrap optionals "Binds" value of optional to new variable if let definitelyAnInt = maybeAnInt { print("maybeAnInt contains (definitelyAnInt)") }
  • 9. IMPLICITLY UNWRAPPED OPTIONALS Trigger a runtime error when accessed if the value is nil Denoted using a ! var alwaysAString: String! = nil let stringLength = alwaysAString.characters.count
  • 10. OPTIONAL CHAINING Cannot access optional without unwrapping Chaining only accesses if value not nil var optionalArray: [Int]? = [ 1, 2, 3, 4 ] var arrayLength = optionalArray?.count
  • 11. ARRAYS Can only contain a single type Immutable arrays use let, mutable use var count, isEmpty, append, insert let groceryList: [String] = ["eggs", "milk"] var mutableGroceryList = ["eggs", "milk"] var item = mutableGroceryList[0]
  • 12. DICTIONARIES Hold key-value pairs Keys and values each can only be one type Best to use optional binding when accessing var cities = ["New York City" : "USA", "London" : "UK"] cities["London"] cities["London"] = nil
  • 13. CLASSES VS STRUCTS class PersonRefType { let name:String var age:Int // .. } // 1 let peter = PersonRefType(name: "Peter", age: 36) // 2 let peter2 = peter // 3 peter2.age = 25 // peter {"Peter", 25} // peter2 {"Peter", 25}
  • 14. CLASSES VS STRUCTS struct Person { let name:String var age:Int } // 1 let petra = Person(name:"Petra", age:25) // 2 var petra2 = petra // 3 petra2.age = 20 // petra {"Petra", 25} // petra2 {"Petra", 20}
  • 16. ERROR HANDLING Functions and methods can throw Calling functions need to handle errors
  • 17. ERROR HANDLING enum TripError: ErrorType { case NoWaypointsProvided } func createTrip() throws { throw TripError.NoWaypointsProvided } func buttonTapped() { do { try createTrip() } catch TripError.NoWaypointsProvided { print("oh-oh") } catch { print("other error") } }
  • 18. GUARD Alternative to optional binding func printRating() { guard let customerRating = rating?.customerRating, merchantRating = rating?.merchantRating, ratingDate = rating?.ratingDate else { return } print("Customer: (customerRating), Merchant: (merchantRating), Rating Date: (ratingDate)") }
  • 19. PROTOCOL EXTENSIONS Provide implementation as part of protocol protocol Vehicle { var speed: Double { get set } func travelDuration(distance: Double) -> Double } extension Vehicle { func travelDuration(distance: Double) -> Double { return distance / speed } }