Search code examples
iosswiftnsarrayswift2nspredicate

Could not cast value of type '()' (0x2c2fb50) to 'Swift.AnyObject


Code:

let Predicate = NSPredicate(format: "self CONTAINS[cd] %@", searchText)
let result:NSArray  = arrCountryList?.filterUsingPredicate(Predicate) as! AnyObject! as! NSArray
arrCountryList = result.mutableCopy() as! NSMutableArray

I have a list of countries in an array.

I try to filter using NSPredicate, but it gives this error.

How to solve this?


Solution

  • let Predicate = NSPredicate(format: "self CONTAINS[cd] %@", searchText)
    
    let result:NSArray  = arrCountryList.filteredArrayUsingPredicate(Predicate)
    
    arrCountryList = result.mutableCopy() as! NSMutableArray