The code example below shows how I search by the “Name” string in a plist with an array with dictionaries. Now I’ve added two UISliders in the view: sliderOne and sliderTwo. I want to use them as second critera when searchButtonPressed, meaning:
resultObjectsArray now containing the objects where objectName contains nameString (like the example) AND objectPrice is between value of sliderOne and sliderTwo.
But if value of sliderOne is higher than value from slider two, skip this criteria.
Can you show me how this can be done, using the example below? Price is a Number (real) in the plist dictionary like “99,90”.
-(IBAction)searchButtonPressed:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Objects" ofType:@"plist"];
allObjectsArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSString *nameString = [NSString stringWithFormat:@"%@", [nameTextField text]];
resultObjectsArray = [NSMutableArray array];
for(NSDictionary *object in allObjectsArray)
{
NSString *objectName = [object objectForKey:@"Name"];
NSString *objectPrice = [wine objectForKey:@"Price"];
NSRange range = [objectName rangeOfString:nameString options:NSCaseInsensitiveSearch];
if(range.location != NSNotFound)
[resultObjectsArray addObject:object];
}
Thanks!
I think I understand your question, in which case wouldn’t it be enough to just change the condition
with
Let me know if that works for you!