Can someone tell me what's wrong with my approach? the error is
- Type 'User' does not conform to protocol 'Decodable'
- Type 'User' does not conform to protocol 'Encodable'
I have tried to replace the null string for Var id, pushId and avatarLink with String.self but no avail either.
Please help
struct User: Codable, Equatable{ var id = "" var username = String.self var email = String.self var pushId = "" var avatarLink = "" var status = String.self static var currentId: String { return Auth.auth().currentUser!.uid } static var currentUser: User? { if Auth.auth().currentUser != nil { if let dicctionary = UserDefaults.standard.data(forKey: kCURRENTUSER) { let decoder = JSONDecoder() do { let userObject = try decoder.decode(User.self, from: dicctionary) return userObject } catch { print("Error decoding user from user defaults ", error.localizedDescription) } } } return nil } static func == (lhs: User, rhs: User) -> Bool { lhs.id == rhs.id } }