如何使用swift以swift字典格式创建类型存储引用的字段。我继续收到错误说FIRStorageReference。预先感谢您的帮助。 这是下面的代码,photoRef是一个存储参考:
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
中找到)'
答案 0 :(得分:1)
您无法在Firestore中存储FIRStorageReference类型的对象。而是将FIRStorageReference对象转换为字符串,并存储该字符串。您可以使用bucket和fullPath的某种组合来构建符合您需求的字符串。
答案 1 :(得分:0)
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!")
}
}