Skip to content

Instantly share code, notes, and snippets.

@chakrit
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakrit/04688ff895fa34a1d4bd to your computer and use it in GitHub Desktop.
Save chakrit/04688ff895fa34a1d4bd to your computer and use it in GitHub Desktop.
Swift ranges weirdness.
import Foundation
let a = 1
let b = 10
func thisFailsToCompile() -> Bool {
// type 'Range<Int>' does not conform to protocol 'IntervalType'
let range = a..<b
return range ~= 3
}
func butThisIsOk() -> Bool {
return a..<b ~= 3
}
func thisIsAlsoOk() -> Bool {
let range: HalfOpenInterval<Int> = a..<b
return range ~= 3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment