I’m making an attempt my consumer put up from firebase firestore however I’m receiving an error
Can’t assign worth of sort ‘QuerySnapshot’ to sort ‘[Post]’
func fetchPosts() async throws -> [Post] {
self.posts = strive await FirestoreConstants
Argument handed to name that takes no arguments
.getDocuments(as: Publish.self)
class FeedService {
personal var posts = [Post]()
personal let userService = ThirdUserService()
func fetchPosts() async throws -> [Post] {
self.posts = strive await FirestoreConstants
.PostsCollection
.order(by: "timestamp", descending: true)
.getDocuments(as: Publish.self)
await withThrowingTaskGroup(of: Void.self) { group in
for put up in posts {
group.addTask { strive await self.fetchPostUserData(put up) }
}
}
return posts
}
PostData
import Firebase
import FirebaseFirestoreSwift
import SwiftUI
import AVKit
struct NewPost: Identifiable, Codable {
let id: String
let videoUrl: String
let ownerUid: String
let caption: String
var likes: Int
var commentCount: Int
var saveCount: Int
var shareCount: Int
var views: Int
var thumbnailUrl: String
var timestamp: Timestamp
var consumer: Userss?
var didLike = false
var didSave = false
init(from decoder: Decoder) throws {
let container = strive decoder.container(keyedBy: CodingKeys.self)
self.id = strive container.decode(String.self, forKey: .id)
self.videoUrl = strive container.decode(String.self, forKey: .videoUrl)
self.ownerUid = strive container.decode(String.self, forKey: .ownerUid)
self.caption = strive container.decode(String.self, forKey: .caption)
self.likes = strive container.decode(Int.self, forKey: .likes)
self.commentCount = strive container.decode(Int.self, forKey: .commentCount)
self.saveCount = strive container.decode(Int.self, forKey: .saveCount)
self.shareCount = strive container.decode(Int.self, forKey: .shareCount)
self.views = strive container.decode(Int.self, forKey: .views)
self.thumbnailUrl = strive container.decode(String.self, forKey: .thumbnailUrl)
self.timestamp = strive container.decode(Timestamp.self, forKey: .timestamp)
self.consumer = strive container.decodeIfPresent(Userss.self, forKey: .consumer)
self.didLike = strive container.decodeIfPresent(Bool.self, forKey: .didLike) ?? false
self.didSave = strive container.decodeIfPresent(Bool.self, forKey: .didSave) ?? false
}
init(
id: String,
videoUrl: String,
ownerUid: String,
caption: String,
likes: Int,
commentCount: Int,
saveCount: Int,
shareCount: Int,
views: Int,
thumbnailUrl: String,
timestamp: Timestamp,
consumer: Userss? = nil,
didLike: Bool = false,
didSave: Bool = false
) {
self.id = id
self.videoUrl = videoUrl
self.ownerUid = ownerUid
self.caption = caption
self.likes = likes
self.commentCount = commentCount
self.saveCount = saveCount
self.shareCount = shareCount
self.views = views
self.thumbnailUrl = thumbnailUrl
self.timestamp = timestamp
self.consumer = consumer
self.didLike = didLike
self.didSave = didSave
}
}
extension NewPost: Hashable { }
extension NewPost: Equatable {
static func == (lhs: NewPost, rhs: NewPost) -> Bool {
return lhs.id == rhs.id
}
}