Reputation: 1105
I'm getting the error:
int is not convertible to NSRange
on var range:NSrange = 0
:
let predicate = NSPredicate(block: { (city: AnyObject!, b: [NSObject : AnyObject]!) -> Bool in
var range:NSRange = 0; //convert error happens here on 0
if city is NSString {
range = city.rangeOfString(searchBarText, options: NSStringCompareOptions.CaseInsensitiveSearch)
}
return range.location != NSNotFound
})
any ideas on how to fix this?
Upvotes: 0
Views: 594
Reputation: 285079
NSRange
is a struct
with members location
and length
, not an Int
use the initializer
var range: NSRange = NSRange(location:0, length:0)
or the convenience function
var range: NSRange = NSMakeRange(0, 0)
Upvotes: 1
Reputation: 93161
Your init statement was wrong. NSRange
is a struct with a location
and a range
value. Change that to:
var range = NSMakeRange(NSNotFound, 0)
Upvotes: 4