Search code examples
firebasegoogle-cloud-firestoresnapshot

documentReference.data(as: ) not available anymore in Firestore?


I'm trying to access the documentReference.data(as: ) but it seems like it wouldn't show on my end. I was wondering if this method is deprecated? if so is there any alternative method I can use to map a document reference to a Swift type.

Here's a screenshot of my code:

documentReference.data(as: ) not showing

What I'm try to do is something like this.

func fetchOccupants() async throws -> [Occupant] {
    let snapshot = try await occupantsRef.getDocuments()
    
    
    return snapshot.documents.compactMap { document in
        try? document.data(as: Occupants.self)
    }
}

Solution

  • After a few days of testing and reading some documentation I finally solved it. It seems like using Cocoapods to add FirebaseFirestoreSwift is not working, so I tried using Swift Package Manager instead since it's more updated Package Manager for Swift.

    Following this method works for me link