我想从struct更新值,这是我的struct代码。
struct Usersdata {
let uid:String?
let facebook:String?
let google : String?
let name : String?
let age : Int?
let birthday : String?
let smokeage : Int?
let smokeaddiction : Int?
let smokebrand : String?
let gold : Int?
let score : Int?
let fish : Int?
let shit : Int?
let userimage : String?
init(aDoc: DocumentSnapshot) {
self.uid = aDoc.get("uid") as? String ?? ""
self.facebook = aDoc.get("facebook") as? String ?? ""
self.google = aDoc.get("google") as? String ?? ""
self.name = aDoc.get("name") as? String ?? ""
self.age = aDoc.get("age") as? Int ?? 0
self.birthday = aDoc.get("birthday") as? String ?? ""
self.smokeage = aDoc.get("smokeage") as? Int ?? 0
self.smokeaddiction = aDoc.get("smokeaddiction") as? Int ?? 0
self.smokebrand = aDoc.get("smokebrand") as? String ?? ""
self.gold = aDoc.get("gold") as? Int ?? 0
self.score = aDoc.get("score") as? Int ?? 0
self.fish = aDoc.get("fish") as? Int ?? 0
self.shit = aDoc.get("shit") as? Int ?? 0
self.userimage = aDoc.get("userimage") as? String ?? ""
}
}
我从我的查询函数获得值,如下所示
func queryAUser() {
let docRef = self.db.collection("Users").document(userID).collection("userdata").document("userdata")
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let aUser = Usersdata(aDoc: document)
self.local_userdata = aUser
} else {
print("Document does not exist")
}
}
}
我可以使用local_userdata来获取我的值,但是我现在想要更新Firestore的新值。
是否有从Usersdata.struct更新值的解决方案?
https://stackoverflow.com/questions/52994499
复制相似问题