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

Fix Swift 3.1 warnings. #73

Merged
merged 3 commits into from
Apr 20, 2017
Merged

Fix Swift 3.1 warnings. #73

merged 3 commits into from
Apr 20, 2017

Conversation

mluisbrown
Copy link
Contributor

No description provided.

@@ -60,9 +60,9 @@ func ==(lhs: Response, rhs: Response) -> Bool {
extension Response: Hashable {

var hashValue: Int {
let body = self.body == nil ? "\(self.body)" : ""
let error = self.error == nil ? "\(self.error)" : ""
let body = self.body == nil ? "" : "\(self.body!)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no, don't use force unwrapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RuiAAPeres would this work for you?

let body = "\(self.body ?? Data())"
let error = "\(self.error ?? NSError())"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mluisbrown can you please change to this?

let body = self.body.map { "\($0)" } ?? ""
let error = self.error.map { "\($0)" } ?? ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@dmcrodrigues dmcrodrigues merged commit 4479f4d into master Apr 20, 2017
@dmcrodrigues dmcrodrigues deleted the swift31-fixes branch April 20, 2017 22:28
@RuiAAPeres
Copy link
Member

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

Successfully merging this pull request may close these issues.

3 participants