Skip to content

RameshiOS/LeaderBoard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Swift Leaderboard App

An advanced Leaderboard System built in Swift, demonstrating the power of Hashable, Equatable, Comparable, and Identifiable protocols. ๐Ÿš€

๐Ÿ“Œ Features

  • ๐Ÿ† Sort Players by score using Comparable
  • ๐Ÿ” Fast Lookups in dictionaries using Hashable
  • โœ… Check Equality of players using Equatable
  • ๐Ÿ”— SwiftUI Integration with Identifiable

๐Ÿ› ๏ธ Installation

  1. Clone this repository:
    git clone https://github.com/yourusername/leaderboard-app.git
  2. Open the project in Xcode.
  3. Run the app on a simulator or device.

๐Ÿš€ How It Works

Player Model Implementation

struct Player: Equatable, Hashable, Comparable, Identifiable {
    let id: UUID
    let name: String
    let score: Int
    
    static func == (lhs: Player, rhs: Player) -> Bool {
        return lhs.name == rhs.name && lhs.score == rhs.score
    }
    
    func hash(into hasher: inout Hasher) {
        hasher.combine(name)
        hasher.combine(score)
    }
    
    static func < (lhs: Player, rhs: Player) -> Bool {
        return lhs.score > rhs.score // Higher score ranks first
    }
}

Sorting the Leaderboard

var players: [Player] = [
    Player(id: UUID(), name: "Alice", score: 1500),
    Player(id: UUID(), name: "Bob", score: 1200),
    Player(id: UUID(), name: "Charlie", score: 1800)
]

let sortedPlayers = players.sorted()

๐Ÿ“‚ Full Blog Post

Check out my detailed article explaining Swift protocols with real-world use cases and examples! ๐ŸŽฏ ๐Ÿ”— Read here: [Your Blog Link]

๐Ÿ’ก Contributing

Feel free to open issues or submit pull requests to improve the project.

๐Ÿ“œ License

This project is open-source and available under the MIT License.


๐Ÿš€ Follow me on LinkedIn for more Swift tips!

#Swift #iOSDevelopment #SwiftUI #Leaderboard #Coding

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages