SHARE
TWEET

Untitled

a guest Jun 18th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class UserModel : Codable, Identifiable{
  2.  
  3. var id: String? = nil
  4. var email: String?
  5. var name: String?
  6. var pfpUrl: String?
  7. var roles: [Roles]?
  8.  
  9.   init(email: String, name: String, pfpUrl: String, roles: [Roles]) {
  10.     self.email = email
  11.     self.name = name
  12.     self.pfpUrl = pfpUrl
  13.     self.roles = roles
  14.   }
  15.  
  16.  }
  17.      
  18. struct Roles: Codable {
  19.  
  20. var role: String?
  21. var vkNumber: String?
  22.  
  23. enum CodingKeys: String, CodingKey{
  24.     case role = "student"
  25.     case vkNumber = "800000015"
  26.  
  27. }
  28.      
  29. extension DocumentSnapshot {
  30.  
  31. func decode<T: Decodable>(as objectType: T.Type, includingId: Bool = true) throws  -> T {
  32.  
  33.     var documentJson = data()
  34.     if includingId {
  35.  
  36.         documentJson?["id"] = documentID
  37.     }
  38.  
  39.     let documentData = try JSONSerialization.data(withJSONObject: documentJson ?? "null", options: [])
  40.     let decodedObject = try JSONDecoder().decode(objectType, from: documentData)
  41.  
  42.     return decodedObject
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top