You can think of dozens of examples of sorting objects with a natural sort order.
Integers? Sort by value, naturally.
Utensils? Sort them in your drawer by forks, knives, and spoons
Bedroom closet? Jackets, Shirts, Trousers
Cash Register? Ones, Fivers, Tenners
What about albums? Sort by Artist? or by Genre? What's the natural order?
// This is a one time rule telling swift to sort Wiki articles by Title.
pages = items.query.pages.values.sorted { $0.title < $1.title }
// This tells Swift to sort based on the natural order for Wiki pages.
// But, sure, you must first tell Swift what this natural order is.
pages = items.query.pages.values.sorted()
So consider the bigger lesson here. Maybe the goal isn't how to add more code to a structure and bury the sorting code. Perhaps the goal is to learn a new Swift technique.
Protocol Lesson
It seems @twostraws is reinforcing a lesson about adding Protocols to data structures. By implementing Protocols, your structures can benefit from a windfall of new and useful capabilities. Indeed, he's sharing the magic of the Comparable
protocol. This protocol requires you to implement one function that returns a boolean when two of your custom objects are compared. Does a fork sort higher than a spoon? Do shirts sort higher than trousers? You decide.
You're in control of how your objects sort.
For Wiki articles, you can implement the protocol and compare the titles of two Wiki articles. You're in charge and you're telling swift the natural sort order for Wiki articles is their titles.
When you implement the Comparable
protocol you can sort a list of students, a list of museum sculptures, a list of favorite SF Symbols. The thing is, you get to decide the natural sort order by implementing the Comparable
protocol.
Inserting Links
Here's another lesson to consider. Rather than having messages with rather long URLs that span the width of a message, please take a moment to review how to embed a link in the forum messages. You can give each link a brilliant title, whilst hiding the messy URL within the link! Nice! 10-points to Hufflepuff!
See -> Day 72 Lesson on Comparable