conorgriffin
conorgriffin

Reputation: 4339

Why am I getting the error "Type of expression is ambiguous without more context"?

In the following code, I'm trying to check a domain name for a match on some search text. The search text is in the variable searchText but Xcode is giving me an error stating:

Type of expression is ambiguous without more context

The caret is pointing at the first character of linkRange.location != NSNotFound in the last line. I can't figure out what I'm doing wrong and the error message is not very helpful

// search domain name
let linkText: NSString = dict["link"]!
let url: NSURL = NSURL(string: linkText as String)!
let domain = url.host
let linkRange = domain!.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch)
let foundInLink = linkRange.location != NSNotFound

Upvotes: 0

Views: 394

Answers (1)

Dániel Nagy
Dániel Nagy

Reputation: 12045

rangeOfString gives you back a Range not an NSRange, and it doesn't have a location property. So you should have to do somethink like this in the last line:

let foundInLink = linkRange != nil

Upvotes: 2

Related Questions