Reputation: 103
I have an array which contains lots of info like lat,lon,city name etc.But all this info stored by class object.
("<GetCityList: 0x1fd334d0>",
"<GetCityList: 0x1fd33560>",
"<GetCityList: 0x1fd33310>",)
my array is looking like this.if i want city name then first i create GetCityList object and then object.cityName. Now i have to search lat and lon by comparing cityName.so how can i do,because it consumes too much time?can i use predicate ?how?
Upvotes: 0
Views: 132
Reputation: 38249
Use it in this way also:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"cityName contains %@", @"cityNamehere"]
NSMutableArray *filtered = [cityListArray filterUsingPredicate:predicate];
Upvotes: 0
Reputation: 22726
Let say you have an array of cityList and want to Filter this by city name you can do
NSPredicate *cityNamePredicate = [NSPredicate predicateWithFormat:@"cityName contains[c] %@", @"cityName"]
NSArray *filteredCityList = [cityList filteredArrayUsingPredicate:cityNamePredicate];
Above filteredCityList will be your required filtered array whatever you passed in parameter. Here [cd] means case and diatric insensitive
You can refer this tutorial for further exploring NSPredicate.
Upvotes: 3
Reputation: 654
Example:
self.data = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"To Airport",@"TO/AIR", nil] forKeys:[NSArray arrayWithObjects:kName,kCode, nil]],
[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Point-to-Point",@"PTP", nil] forKeys:[NSArray arrayWithObjects:kName,kCode, nil]],[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"From Airport",@"FR/AIR", nil] forKeys:[NSArray arrayWithObjects:kName,kCode, nil]], nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(name CONTAINS[cd] %@)",searchText];
self.searchableData = [self.data filteredArrayUsingPredicate:predicate];
Based on this you can replace name with cityName.
Upvotes: 0