Persisting Geofence Events
To determine the time spent outside each day, we need the time the device exited and reentered the region. Let’s first create an enum type that helps to differentiate between entering and exiting. Add a new file to the project using the shortcut ⌘N, choose the Swift File template, and save it as UpdateType.swift. Add the following enum to the file:
| enum UpdateType : String, Codable { |
| case enter |
| case exit |
| } |
enums in Swift let you define a type that can take a limited number of values, in this case either enter or exit. Add another Swift file, save it as RegionUpdate.swift, and add the following struct to it:
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.