I'm not sure if it's a bug in XCode or I didn't understand ranges in Swift. Here is some code to show how range works:
let range = 0..<5
contains(range, 0) // true
contains(range, 5) // false
range.startIndex == 0 // true
range.endIndex == 5 // true
let str = "Hello, playground"
str.rangeOfString("Hello")! // 0..<5
Great! Now let's use it real code:
let str = "Hello, playground"
if let range = str.rangeOfString("Hello") {
if range.startIndex == 0 {
print("str starts with 'Hello'")
}
}
I'm getting following error in line that reads if range.startIndex == 0 {
Cannot invoke '==' with an argument lis of type (String.index, IntegerLiteralConvertible)'