100 Days of SwiftUI

Day 71

2026-07-24

Project 14, part 4

Using Wikipedia data

Downloading data from Wikipedia

The Wikipedia API is gnarly man! However, commenters on the gist have provided a readable version. The only problem is, I couldn’t figure out how to use it in the rest of the function, until I realized it already is a URL? so I didn’t need to go back and forth between Strings

Cover image of The Gnarly Man by L Sprague De Camp
guard let url = components.url else {
    print("Bad URL: \(components)")
    return
}

The tutorial has us using + with Text which has been deprecated as of iOS 26.

ForEach(pages, id: \.pageid) { page in
    Text(page.title)
        .font(.headline)
    + Text(": ") +
    Text("Page description here")
        .italic()
}

So what can we do to have multiple formats in Text? We put it all in one line.

ForEach(pages, id: \.pageid) { page in
   Text("""
   \(Text(page.title).font(.headline)): \
   \(Text("Page description here"ß).italic())
   """)
}

Sorting Wikipedia results

conforming to Comparable has only a single requirement: we must implement a < function that accepts two parameters of the type of our struct, and returns true if the first should be sorted before the second

I didn’t realize it was required

We added var description: String { terms?["description"]?.first ?? "No further information" } to our Page struct, and now the text view is

ForEach(pages, id: \.pageid) { page in
    Text("""
    \(Text(page.title).font(.headline)): \
    \(Text(page.description).italic())
    """)
}

The sorting is based on the article’s title. Is that the best way? I dunno. But it works.