I’ve two collections in Firestore:
The exercises
assortment consists of a identify
, a kind
and an array of references to workouts within the Train
assortment.
The exercises
assortment seems like this:
My downside is that once I’m making an attempt to get the exercises within the Exercises
assortment, I am doing it like this:
let workoutDocuments = strive await self.retailer.assortment("/exercises").getDocuments().workoutDocuments
for workoutDocument in paperwork {
let workoutCodable = workoutDocument.knowledge(as: WorkoutCodable.self)
// MARK: - WorkoutCodable
struct WorkoutCodable: Identifiable, Codable, Hashable {
@DocumentID var id: String?
// var workouts: [ExerciseCodable]
var identify: String?
var kind: WorkoutTypeCodable
}
}
If the workouts array declaration is commented, then all of it works tremendous. Nonetheless, if take away the touch upon the var workouts: [ExerciseCodable]
then I’ve an issue:
Error getting the benchmark exercises: Swift.DecodingError.typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "exercises", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "Anticipated to decode Dictionary<String, Any> however discovered FIRDocumentReference as an alternative.", underlyingError: nil))
How can I fetch all these workouts saved within the workouts
array?
Thanks!