I have this class
class UserModel: NSObject {
public struct User: Codable {
// User data
var id: String?
var name: String?
var surname: String?
var phone: String?
var email: String?
// Admin data
var isStudent: Bool?
var isTeacher: Bool?
var isAdmin: Bool?
// Wallet / Private data
var wallet = Wallet() //This is another struct
enum CodingKeys: String, CodingKey, CaseIterable {
case name
case surname
case phone
case email
case isStudent
case isTeacher
case isAdmin
}
}
I have a firebase connected to the project. Data keys in cloudstorage exactly matches those keys in user struct. What I want is to make a function that I could say "hey, give me name and surname" and it will make smth like:
func somefunc(here are name and surname reference) {
db.collection("users").document(uid).getDocument { (document, error) in
if let document = document, document.exists {
let user = UserModel.User()
user.name = document.get(name)
user.surname = document.get(surname)
return user
}
}
}
And if I will call someFunc(only email here)
it should only make smith like user.email = document.get(email)
. I tried some options but I had no luck in it
question from:
https://stackoverflow.com/questions/65865116/swift-struct-firebase-cloudstorage 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…