Calculating the Outside Duration

To calculate the outside duration, we need a type to store the weekday and how long the user spent outside on that day. Add a new Swift file, save it as DayEntry.swift, and add the following struct to DayEntry.swift:

 struct​ ​DayEntry​ : ​Hashable​ {
 let​ duration: ​TimeInterval
 let​ weekday: ​String
 }

This struct conforms to Hashable because we’ll iterate over an array of DayEntry objects later in this chapter, and this works only with hashable objects. Hashing is the process of generating a so-called hash value from some kind of input using a hash function. The hash value usually has a fixed size and is optimized to be compared quickly. You don’t ...

Get Build Location-Based Projects for iOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.