Fix Swift 3.1 warnings. - #73
Merged
Merged
Conversation
Closed
RuiAAPeres
reviewed
Apr 20, 2017
| var hashValue: Int { | ||
| let body = self.body == nil ? "\(self.body)" : "" | ||
| let error = self.error == nil ? "\(self.error)" : "" | ||
| let body = self.body == nil ? "" : "\(self.body!)" |
Member
There was a problem hiding this comment.
Yeah, no, don't use force unwrapping.
Contributor
Author
There was a problem hiding this comment.
It's force unwrapping in a context where self.body is guaranteed to be not nil. What alternative would you suggest? Incidentally, the previous code was broken as the logic was the opposite of what was intended.
Contributor
Author
There was a problem hiding this comment.
No, because self.body is a Data and "" is a String, and we want the result to be a String. In the case of the body this compiles:
let body = "\(self.body ?? Data())"
But the equivalent for the Error does not...
Contributor
Author
There was a problem hiding this comment.
@RuiAAPeres would this work for you?
let body = "\(self.body ?? Data())"
let error = "\(self.error ?? NSError())"
Member
There was a problem hiding this comment.
@mluisbrown can you please change to this?
let body = self.body.map { "\($0)" } ?? ""
let error = self.error.map { "\($0)" } ?? ""
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

No description provided.