Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserModel : Codable, Identifiable{
- var id: String? = nil
- var email: String?
- var name: String?
- var pfpUrl: String?
- var roles: [Roles]?
- init(email: String, name: String, pfpUrl: String, roles: [Roles]) {
- self.email = email
- self.name = name
- self.pfpUrl = pfpUrl
- self.roles = roles
- }
- }
- struct Roles: Codable {
- var role: String?
- var vkNumber: String?
- enum CodingKeys: String, CodingKey{
- case role = "student"
- case vkNumber = "800000015"
- }
- extension DocumentSnapshot {
- func decode<T: Decodable>(as objectType: T.Type, includingId: Bool = true) throws -> T {
- var documentJson = data()
- if includingId {
- documentJson?["id"] = documentID
- }
- let documentData = try JSONSerialization.data(withJSONObject: documentJson ?? "null", options: [])
- let decodedObject = try JSONDecoder().decode(objectType, from: documentData)
- return decodedObject
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement