Bucket List SwiftUI app introduction
In this project we’re going to build an app that lets the user build a private list of places on the map that they intend to visit one day, add a description for that place, look up interesting places that are nearby, and save it all to the iOS storage for later.
Adding conformance to Comparable for custom types
We’ve seen the
Comparable protocol before in this course. It contains functions that allow us to compare specific data types. SwiftUI does a lot of this for us in the background for
Strings, however, what if we want to add this functionality to our own custom types? Well, it just so happens that that’s possible!
Writing data to the documents directory
Previously we looked at how to read and write data to
UserDefaults, which works great for user settings or small amounts of JSON. However, it’s generally not a great place to store data, particularly if you think you’ll start storing more in the future.
In this app we’re going to be letting users create as much data as they want, which means we want a better storage solution than just throwing things intoHacking with Swift, Paul Hudson (@twostraws)
UserDefaultsand hoping for the best. Fortunately, iOS and SwiftUI make it very easy to read and write data from device storage, and in fact all apps get a directory for storing any kind of documents we want. Files here are automatically synchronized with iCloud backups, so if the user gets a new device then our data will be restored along with all the other system data – we don’t even need to think about it.
It’s not quite as easy as it sounds, but it’s not too bad really. Paul explains it all!
That it for day 68! This has been a relatively short day compared to the previous days where UIKit featured heavily, so it was a nice change of pace. We’ll be diving further into the Bucket List app in the coming days. Time to recharge for now!