Your First iOS & SwiftUI App: Polishing the App, Episode 38: Challenge: Leaderboard Data Model | raywenderlich.com

Using what you learned about Swift ararys, try integrating leaderboard entries into the app’s data model.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/28797859-your-first-ios-swiftui-app-polishing-the-app/lessons/38

Hi.

There is an error in the transcript: the code in the transcript matches the video when the addToLeaderboard() func is first described, but the code in line 3 was changed later in the video because it didn’t compile.

mutating func addToLeaderboard(points: Int) {
  leaderboardEntries.append(LeaderboardEntry(points: points, date: Date()))
  leaderboardEntries.sort { $0.points > $1.points }
}

should be

mutating func addToLeaderboard(points: Int) {
  leaderboardEntries.append(LeaderboardEntry(points: points, date: Date()))
  leaderboardEntries.sort { $0.score > $1.score }
}