Reputation: 188
I have two classes like below:
class City : NSObject{
var header:String? = nil
var areas:NSMutableArray? = nil //Contain array of Area
//Return array of City objects
class func generate(cityCount:NSInteger) -> NSMutableArray{...}
}
and
class Area : NSObject{
var title:String? = nil
var address:String? = nil
}
//Return array of Area objects
class func generate(areaCount:NSInteger) -> NSMutableArray {...}
Now, I have Array of City like this declared in my viewcontroller:
var cities = City.generate(200)
and when I search the header inside using NSPredicate it work perfectly
let pred = NSPredicate(format: "SELF.header CONTAINS %@",searchString)
let filteredCities = self.cities.filteredArrayUsingPredicate(pred)
But when I search the cities->areas->address
(I want to search address). It is not working. It is always return 0 object. Here what I am trying:
let pred = NSPredicate(format: "SELF.areas.address CONTAINS %@",searchString) //name
let filteredCities = (self.cities as NSArray).filteredArrayUsingPredicate(pred)
EDIT
I need only the area object that contain matching address. I have tried:
let pred = NSPredicate(format: "ANY areas.address CONTAINS %@",searchString)
This is giving the City object with all area object.
Thanks in advance.
Upvotes: 0
Views: 965
Reputation: 26
Try this bro,
let pred = NSPredicate(format: "SELF contains[c] %@",searchString) let filteredCities = self.area.filteredArrayUsingPredicate(pred)
Upvotes: 0
Reputation: 72410
Have try like this
let pred = NSPredicate(format: "ANY areas.address CONTAINS %@",searchString)
Upvotes: 1