Welcome to day 71 of the 100 Days of SwiftUI! Yesterday, we expanded on MapKit and the functionality it offers us and our users. Today, we’re looking into how to download data from Wikipedia for use in our app. Let’s dive in!
Downloading data from Wikipedia in SwiftUI
To make this whole app more useful, we’re going to modify our
Hacking with Swift, Paul Hudson (@twostraws)EditView
screen so that it shows interesting places. After all, if visiting London is on your bucket list, you’d probably want some suggestions for things to see nearby. This might sound hard to do, but actually we can query Wikipedia using GPS coordinates, and it will send back a list of places that are nearby.
In essence, we’re going to fetch data from Wikipedia and then immediately show it to our users in the UI.
Sorting Wikipedia results
When the results from Wikipedia are returned to us, they are sorted by their page ID on Wikipedia itself, not by something we’ve defined in SwiftUI yet. This is not particularly useful for us, nor our users. To solve this, we’ll use a custom closure to sort the results in a way that makes sense and is useful to users.
Wrap up
And that’s it for day 71! Another short and easy day, but a very fun one nonetheless. It makes what we’ve learned really tangible when we’re actually using a huge resource like Wikipedia within our app to fetch data from and show in our UI. Tomorrow is the last day for this project, so time to recharge and get ready! Until then.
100 Days of SwiftUI – Day 71