如何在swift中为Firestore添加存储参考? [英] How do you add a storage Reference in swift for Firestore?
问题描述
如何使用swift以swift字典格式创建类型为storage reference的字段.我不断收到错误消息,说是FIRStorageReference.预先感谢您的帮助. 这是下面的代码,photoRef是存储引用:
How do you create a field of type storage reference in the swift dictionary format using swift. I keep on getting an error saying that FIRStorageReference. Thank you in advance for your help. This is the code below, photoRef is a storage reference:
let newFirePhotoRef = newUserRef.collection("Photos").document()
photoRef = photoRef.child(newFirePhotoRef.documentID)
newFirePhotoRef.setData([
"Date":Date(),
"Photo Reference in Storage": photoRef
])
这是我收到的错误:
由于未捕获的异常'FIRInvalidArgumentException'而终止应用程序,原因:'不支持的类型:FIRStorageReference(在字段Photo Reference in Storage
中找到)'
Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 'Unsupported type: FIRStorageReference (found in field Photo Reference in Storage
)'
我想迅速创建此字段
I would like to create this field in swift
推荐答案
let db = Firestore.firestore()
//this is to store reference
let ref = db.document("listing/v4/content/\(key)")
let dataToWriteInFireStore :[String:Any] = [
"_ref": ref,
"id": 4,
"timestamp": Int(Date().millisecondsSince1970)
]
db.collection("user_favs/v4/\(FIRUserID)").document("user_fav").setData(dataToWiteInFireStore) {
err in
if let err = err {
print("Error writing document: \(err)")
} else {
print("Document successfully written!")
}
}
这篇关于如何在swift中为Firestore添加存储参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!