ios – Cannot fetch knowledge from firestore

0
16
ios – Cannot fetch knowledge from firestore


Each time I attempt to fetch the info again from firestore it throws error and no knowledge is retrieved.

The error:

grpc.server_uri=dns:///firestore.googleapis.com}}: join failed (UNKNOWN:(area:NSPOSIXErrorDomain, code:50, description:The operation couldn’t be accomplished. Community is down)
The information couldn’t be learn as a result of it's lacking.

The code:

struct LeaderboardUser: Codable, Identifiable {
    let id = UUID()
    let username: String
    let rely: Int
}

class LeaderboardVM: ObservableObject {
    
    @Revealed var leaders = [LeaderboardUser]()
    
    var mockData = [
        LeaderboardUser(username: "Jason", count: 432),
        LeaderboardUser(username: "Sean Allen", count: 22),
        LeaderboardUser(username: "Peter", count: 434),
        LeaderboardUser(username: "Paul", count: 344),
        LeaderboardUser(username: "Mike", count: 732),
        LeaderboardUser(username: "Harvey", count: 646)
    ]
    
    struct LeaderboardResult {
        let person: LeaderboardUser?
        let top10: [LeaderboardUser]
    }
    
    init() {
        Process {
            do {
                strive await postStepCountFor(username: "Jack", rely: 22)
                let outcome = strive await fetchLeaderboard()
                DispatchQueue.essential.async {
                    self.leaders = outcome.top10
                }
            } catch {
                print(error.localizedDescription)
            }
        }
    }
    
    func fetchLeaderboard() async throws -> LeaderboardResult {
        let leaders = strive await DatabaseManager.shared.fetchLeaderBoards()
        let top10 = Array(leaders.sorted(by: { $0.rely > $1.rely }).prefix(10))
        let username = UserDefaults.normal.string(forKey: "username")
        
        if let username = username {
            let person = leaders.first(the place: { $0.username == username })
            return LeaderboardResult(person: person, top10: top10)
        } else {
            return LeaderboardResult(person: nil, top10: top10)
        }
    }
    
    func postStepCountFor(username: String, rely: Int) async throws {
        strive await DatabaseManager.shared.postStepCountUpdate(chief: LeaderboardUser(username: username, rely: rely))
    }
}
  1. Knowledge is been saved efficiently on the Firestone however in the case of retrieving the info, it fails.
  2. Please assist me finds the problem I’m dealing with.

LEAVE A REPLY

Please enter your comment!
Please enter your name here