HomeiOS Developmentios - Methods to fetch with async

ios – Methods to fetch with async


I’m attempting to determine methods to construction my code to fetch my consumer knowledge from firebase That is the code i used to fetch my consumer with async however I’m receiving these errors that’s throwing off the remainder of my code

Argument handed to name that takes no arguments

Can’t convert return expression of kind ‘[String : Any]?’ to return kind ‘C’

Insert ‘ as! C’

Can’t convert worth of kind ‘C’ to anticipated argument kind ‘[String : Any]’

Insert ‘ as! [String : Any]’

Incorrect argument label in name (have ‘from:’, anticipated ‘knowledge:’)

Exchange ‘from’ with ‘knowledge’

After I repair these errors I’m left with simply this error on the identical strains

Argument handed to name that takes no arguments

Why am I receiving this error and the way do I repair this code to take away the errors to fetch my consumer knowledge from firebase and show it on my machine ?

import Basis
import Firebase
import FirebaseFirestoreSwift
import FirebaseFirestore
struct FireStore{
    static non-public let db = Firestore.firestore()
        static let userPath: String = "consumer"
        ///Retreives Single consumer
        func fetchUser(id: String) async throws -> UserModelFile{
            return strive await getDocument(path: FireStore.userPath, id: id)
        }
        ///Retreives consumer assortment
        func getAllUsers() async throws  -> [UserModelFile]{
            strive await getSnapshot(path: FireStore.userPath)
        }
        ///Creates a brand new consumer
        func createUser() async throws -> UserModelFile{
            return strive await FireStore.create(path: FireStore.userPath, obj: .init(bio: "Enter bio", username: "New Person"))
        }
        static func create<C>(path: String, obj: C) async throws -> C the place C : Codable {
            strive await db.assortment(path).addDocument(from: obj).getDocument().knowledge(as: C.self)
        }
        
        ///Retrieves a single doc
        non-public func getDocument<C>(path: String, id: String) async throws -> C the place C: Decodable{
            let snapshot = strive await Self.db
                .assortment(path)
                .doc(id).getDocument()
            
            return strive snapshot.knowledge(as: C.self)
        }
        ///Retrieves a set of paperwork
        non-public func getSnapshot<C>(path: String) async throws -> [C] the place C: Decodable{
            let snapshot = strive await Self.db
                .assortment(path)
                .getDocuments()
            return snapshot.paperwork.compactMap { doc in
                do{
                    return strive doc.knowledge(as: C.self)
                }catch{
                    print("(kind(of: self)) :: (#perform) :: ERROR :: nt(error)")
                    return nil
                }
struct UserModelFile: Codable, Identifiable{
    var id: String?{
        ref?.documentID
    }
    @DocumentID var ref: DocumentReference?
    var bio: String
    var username: String
    var profilePic: URL?
}

class UserDataFile: ObservableObject {
    
   
        @Revealed var datas : [UserModelFile] = []
        non-public let retailer: FireStore = .init()
        //Will get all of the customers
        func getAllUsers() async throws{
            datas = strive await retailer.getAllUsers()
        }
        //Will get a single consumer with the id supplied in your picture
        func singleUser() async throws{
            datas = [try await store.fetchUser(id: "ProfileImages")]
        }
    
        //Creates a brand new consumer
        func create() async throws -> UserModelFile {
            return strive await retailer.createUser()
        }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments