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

Contains method in Range #66

Merged
merged 2 commits into from
Apr 3, 2016
Merged

Contains method in Range #66

merged 2 commits into from
Apr 3, 2016

Conversation

RamonGilabert
Copy link
Contributor

I was doing some Networking and wanted to check if the status code was in a range, did this tiny thing. You call it like this:

let OK = 200..<300
OK.contains(response.statusCode)

@hyperoslo/malibu

@RamonGilabert
Copy link
Contributor Author

Pretty sure it goes to Shared since it's Foundation stuff.

@zenangst zenangst merged commit 2bb738f into master Apr 3, 2016
@zenangst zenangst deleted the range branch April 3, 2016 11:57
@zenangst
Copy link
Contributor

zenangst commented Apr 3, 2016

🚀🚀🚀

@RamonGilabert RamonGilabert restored the range branch April 3, 2016 12:06
@vadymmarkov
Copy link
Contributor

@RamonGilabert @zenangst
It can be done with standard functionality:

let OK = 200..<300

if case OK = response.statusCode {
  print("success")
}

@zenangst
Copy link
Contributor

zenangst commented Apr 3, 2016

@vadymmarkov oh, didn't know that 😁

@onmyway133
Copy link
Contributor

@vadymmarkov I learn ☺️

@onmyway133
Copy link
Contributor

I see that we can also use the pattern matching operator

let statusCode = 205
let result = 200..<300 ~= statusCode  // true

@onmyway133 onmyway133 deleted the range branch June 7, 2016 11:59
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.

None yet

4 participants