-
Notifications
You must be signed in to change notification settings - Fork 85
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
Refactor mechanism to deserialize user-defined classes for entries #138
Conversation
9bf3c91
to
92d5cdf
Compare
92d5cdf
to
271607e
Compare
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.
Some minor comments, no change required per se, but would be nice to check.
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) |
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.
Spacing on assignment is not consistent throughout the code. For example, within this same method: https://github.com/contentful/contentful.swift/pull/138/files#diff-0312db99a9cdde535bb9947197e97a8eR148
Either have all of them aligning, or have all of them with proper whitespace. I personally prefer having them with regular whitespacing as it's simpler to read at a glance, and extra whitespace is noisy.
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'll see what i can do! thanks @dlitvakb
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.
so yeah, i'm simply aligning the right hand side for all these methods to the farthest left that they can be and still remained aligned. make sense?
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.
sounds good
var entries: [EntryDecodable] = [] | ||
let contentTypes = decoder.userInfo[DecoderContext.contentTypesContextKey] as! [ContentTypeId: EntryDecodable.Type] | ||
|
||
while entriesJSONContainer.isAtEnd == false { |
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.
while !entriesJSONContainer.isAtEnd {
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 actually like == false
here. It's easy to miss the ! at the start and it gets especially confusing when you have a semantic variable like isAtEnd
. Just my 2c.
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.
yeah, i've chosen as the style for the sdk to use == false
always over !
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 personally prefer conciseness, but I understand that it may get lost in the syntax.
var entries: [EntryDecodable] = [] | ||
let contentTypes = decoder.userInfo[DecoderContext.contentTypesContextKey] as! [ContentTypeId: EntryDecodable.Type] | ||
|
||
while entriesJSONContainer.isAtEnd == false { |
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.
same as previous
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.
Some of this code looks to be duplicated, may there be a way to de-duplicate and reuse it?
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.
unfortunately, these are different types and i'm just initializing a few mutable and immutable variables. i think the only refactor opportunity would be a helper that returns a tuple, but in fact the handling of data inside this json is different while iterating through the container.
var entries: [EntryDecodable] = [] | ||
let contentTypes = decoder.userInfo[DecoderContext.contentTypesContextKey] as! [ContentTypeId: EntryDecodable.Type] | ||
|
||
while entriesJSONContainer.isAtEnd == false { |
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.
Same as previous
TODO before merging:
Fixes #132
Fixes #133
Though not a direct fix for denormalizing the JSON response, the fact that the new mechanism leverages Swift 4's decodable protocol obviates the need to denormalize the json, therefore this fixes #109