I'm trying to come up with a way to extract a image from an HTML page. (I haven't looked up how this is actually done, I'm just trying to come up with something from scratch so don't judge) Anyway, the code I've written so far gets the error "Cannot assign a value of type Range<Index>? to a value of type Range<Int>?"
//variable "html" has type String
let variations = ["img","IMG","Img"]
var tagStart: Range<Int>?
var index = 0
repeat
{
tagStart = html.rangeOfString(variations[index]) //Cannot assign a value of type Range<Index>? to a value of type Range<Int>?
index += 1
}while( tagStart == nil );
Okay, so a the type a Range is composed of is Index, not Int. But when I try to change the declaration I get a "Use of undeclared type 'Index'"
error. So now it's telling me Index is a figment of my imagination?
//variable "html" has type String
let variations = ["img","IMG","Img"]
var tagStart: Range<Index>?
var index = 0
repeat
{
tagStart = html.rangeOfString(variations[index]) //"Use of undeclared type 'Index'"
index += 1
}while( tagStart == nil );
What rangeOfString
produces isn't a range of Index; it's a range of String.Index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With