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

backward compatible options #62

Open
ricocheung opened this issue Nov 10, 2018 · 1 comment
Open

backward compatible options #62

ricocheung opened this issue Nov 10, 2018 · 1 comment

Comments

@ricocheung
Copy link

hi there,
This is quite handy! thanks for sharing.

A question, the decoder throws when Firestore record doesn't exactly match with Class property definition, anyone has recommendation how to handle adding or removing fields between client versions?

for example, myApp version 1 stores object "People" with 2 fields "NameFirst" and "NameLast", using encode and decode are working great.

when i'm doing myApp version 2, when I add a new propoery "PhoneNumber" to People class, the decode throws and return nil, as the new field PhoneNumber doesn't exist in other existing records.

what are the consideration when we decided to throw, rathan than just return nil to the fields that doesn't exist?

thansk!

guard let entry = self.container[key.stringValue] else {
            throw DecodingError.keyNotFound(key, DecodingError.Context(codingPath: self.decoder.codingPath, debugDescription: "No value associated with key \(key) (\"\(key.stringValue)\")."))
        }
@alickbass
Copy link
Owner

Well, in general having extra data in the model will not cause the error, it's only the missing one. So if you have different version of the app, you need to make sure that they only add new data not delete anything. This way you will never have any errors.

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

2 participants