Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyNotFound #83

Open
ChargedEdge opened this issue Dec 3, 2019 · 0 comments
Open

keyNotFound #83

ChargedEdge opened this issue Dec 3, 2019 · 0 comments

Comments

@ChargedEdge
Copy link

keyNotFound No value associated with key CodingKeys
This throws on the accessCodes variable.

I have a custom Codable object that encodes just fine, but I believe that Codable does not encode empty arrays, so when I try to decode, your firebaseDecoder throws an error.

I have to provide a custom decoder init when I have any arrays that can be empty, and I don't append to initially.

This the husk of my class:

class UserSettings {

required init(from decoder: Decoder) throws {
    let map = try decoder.container(keyedBy: CodingKeys.self)
    
    userInfo = try map.decodeIfPresent(.userInfo)
    
    activeAccessCode = try map.decodeIfPresent(.activeAccessCode)
    accessCodes = try map.decodeIfPresent([UserAccessCode].self, forKey: .accessCodes) ?? []
    
    
    activeTeam = try map.decodeIfPresent(.activeTeam)
    teams = try map.decodeIfPresent([String].self, forKey: .teams) ?? []
    
    activeEventID = try map.decodeIfPresent(.activeEventID)
    isManager = try map.decodeIfPresent(.isManager) ?? false
}

var userInfo: UserInfo?

var activeAccessCode: UserAccessCode?
var accessCodes = [UserAccessCode]()

var activeTeam: String?
var teams = [String]()

var activeEventID: String?

var isManager: Bool = false

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant