我有以下内容struct:
struct Recipe: Codable {
@DocumentID var id: String?
var vegetarian: Bool?
}
Run Code Online (Sandbox Code Playgroud)
这就是我解析 Firestore 数据的方式:
do {
let decoder = JSONDecoder()
let recipeToDisplay = try decoder.decode(Recipe.self, from: data!)
let uuid = UUID().uuidString
FirestoreService.createRecipe(
documentId: uuid,
vegetarian: recipeToDisplay.vegetarian ?? false
) { recipeURL in
print("success")
}
} catch {
print("Error parsing response data: \(error)")
}
Run Code Online (Sandbox Code Playgroud)
该catch声明被调用,我收到以下错误消息:decodingIsNotSupported("DocumentID values can only be decoded with Firestore.Decoder")。
我研究过的所有文档都指出我要使用它来JSONDecoder()解析数据,但我在Firestore.Decoder. 我应该有不同的方式来解析数据吗?