-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Config and Location swift decodable conformance #559
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, had two suggestions 👍
KsApi/models/Config.swift
Outdated
self.launchedCountries = try values.decode([Project.Country].self, forKey: .launchedCountries) | ||
self.locale = try values.decode(String.self, forKey: .locale) | ||
|
||
let stripe = try values.decode([String: String].self, forKey: .stripe) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can replace the if/else
here and set the property directly with:
self.stripePublishableKey = try values
.nestedContainer(keyedBy: StripeCodingKeys.self, forKey: .stripe)
.decode(String.self, forKey: .stripePublishableKey)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution!
KsApi/models/Location.swift
Outdated
extension Location: Swift.Decodable { | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case country, displayableName = "displayable_name", id, localizedName = "localized_name", name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think let's put these on new lines for consistency?
So what if we tried to use these decodings in place of the Argo ones? |
We would just need to create a new |
@Scollaco I think we should merge this into a feature branch because it will be unused code until we have the request functions to handle it, what do you think? |
Yeah, I see your point. The only con I see in waiting is that we would have to do the same to all models (make them conform to both Argo and Swift decodable) before merge the feature branch, and this can take a long time and end up forgotten, like it happened in the past. And since these 2 models still conform |
📲 What
Makes the models Config, Location, and Project.Country conform to Swift.Decodable.
🤔 Why
This puts us one step closer to remove the
Argo
library from our codebase. Argo was included in our project before Swift Decodable be released by Apple and its removal will result in the deletion of tons of boilerplate code. Besides that, all the new models no longer conform to the Argo.Decodable protocol.🛠 How
To make the models conform to Swift Decodable, I simply created an extension that conforms to the protocol with a
init(decoder:)
function. The unit tests make sure that the models are being decoded correctly. In the future, we will need to create a newfetch
function on ourService+RequestHelpers
with the correct return type (SignalProducer<A, ErrorEnvelope>) and maybe with akeyDecodingStrategy
.✅ Acceptance criteria
Config decoding shouldn't be affected, since we are not directly using Swift decoder yet.
ConfigTests should pass.
Location decoding shouldn't be affected.
LocationTests should pass.
Project.Country decoding shouldn't be affected.
Project.CountryTests should pass.
Got planned refactors to come
Will add more tests
Need feedback on a design