0

Hi everyone in my projects i having the NSMutableArray containing a Number of Dictionary value,here i filtered by one string, but now i want to filter a multiple strings in this array,that is below is my Array Value

(
        {
        BusAC = "A/C";
        BusFare = 550;
        BusType = "Semi Sleeper";
        TravelsName = "ABC Travels";
    },
        {
        BusAC = "Non A/C";
        BusFare = 600;
        BusType = Seater;
        TravelsName = "Arulmigu Aandal Azahagar Madurai Express";
    },
        {
        BusAC = "A/C";
        BusFare = 1250;
        BusType = Sleeper;
        TravelsName = "GSP  Travels";
    },
        {
        BusAC = "Non A/C";
        BusFare = 350;
        BusType = "Semi Sleeper";
        TravelsName = "Madura  Travels";
    },
        {
        BusAC = "A/C";
        BusFare = 420;
        BusType = Seater;
        TravelsName = "MJT Travels";
    },
        {
        BusAC = "A/C";
        BusFare = 1500;
        BusType = Sleeper;
        TravelsName = "OPR Travels";
    },
        {
        BusAC = "Non A/C";
        BusFare = 730;
        BusType = Seater;
        TravelsName = "MJT Travels";
    }
)

in this i filtered by one string like Sleeper buses

NSPredicate *predicateStr1 = [NSPredicate predicateWithFormat:@"%K == %@", @"BusType",@"Sleeper"];
 NSMutableArray *filteredArray1 = [NSMutableArray arrayWithArray:[totDictArray filteredArrayUsingPredicate:predicateStr1]];

then i filtered by two string like Sleeper & AC

NSPredicate * prediStr=[NSPredicate predicateWithFormat:@"BusType == %@ AND BusAC == %@",@"Sleeper",@"A/C"];

this also working good but now i want to filter like having array & string

String is A/C & Array value is (
    "ABC Travels",
    "GSP  Travels"
) 

i tried this code here the arr is the Above mentioned array

 for (int i=0; i<arr.count; i++)
        {
            NSPredicate * prediStr=[NSPredicate predicateWithFormat:@"TravelsName == %@ AND BusAC == %@",arr[i],@"A/C"];
            NSLog(@"prediStr %@",prediStr);
            NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[totDictArray filteredArrayUsingPredicate:prediStr]];
                NSLog(@"filteredArray %@",filteredArray);
        }

help me..

Updated

(
        {
        Boarding =         (
            "CMBT Omini BS",
            CMBT,
            Vadapalani,
            "Ashok Nagar",
            Thambaram,
            Perungulathur,
            Vandalur
        );
        BusAC = "A/C";
        BusFare = 550;
        BusType = "Semi Sleeper";
        Dropping = "Trichy Bypass";
        TravelsName = "ABC Travels";
    },
        {
        Boarding =         (
            "CMBT Omini BS",
            CMBT,
            Vadapalani,
            "Ashok Nagar",
            Thambaram,
            Perungulathur,
            Vandalur
        );
        BusAC = "Non A/C";
        BusFare = 600;
        BusType = Seater;
        Dropping = "Chathram BS";
        TravelsName = "Arulmigu Aandal Azahagar Madurai Express";
    },
        {
        Boarding =         (
            "CMBT Omini BS",
            CMBT,
            Vadapalani,
            "Ashok Nagar",
            Thambaram,
            Perungulathur,
            Vandalur
        );
        BusAC = "A/C";
        BusFare = 1250;
        BusType = Sleeper;
        Dropping = "Thillai Nagar";
        TravelsName = "GSP  Travels";
    },
        {
        Boarding =         (            
            Thambaram,
            Perungulathur,
            Vandalur
        );
        BusAC = "Non A/C";
        BusFare = 350;
        BusType = "Semi Sleeper";
        Dropping = "Trichy Bypass";
        TravelsName = "Madura  Travels";
    },
        {
        Boarding =         (
            "CMBT Omini BS",
            CMBT,
            Vadapalani,
            "Ashok Nagar",
            Guindy,
            Velachery,
            Thambaram,
        );
        BusAC = "A/C";
        BusFare = 420;
        BusType = Seater;
        Dropping = "Court Campus";
        TravelsName = "MJT Travels";
    },
        {
        Boarding =         (
            "CMBT Omini BS",
            CMBT,
            Thambaram,
            Perungulathur,
            Vandalur
        );
        BusAC = "A/C";
        BusFare = 1500;
        BusType = Sleeper;
        Dropping = "Central BS";
        TravelsName = "OPR Travels";
    },
        {
        Boarding =         (
            "CMBT Omini BS",
            CMBT,
            Vadapalani,
            "Ashok Nagar",
            Thambaram,
        );
        BusAC = "Non A/C";
        BusFare = 730;
        BusType = Seater;
        Dropping = "Omini BS";
        TravelsName = "MJT Travels";
    }
)

in this array i've boarding also in this i want to Filter on the boarding array also that means BusAC is A/c & boarding is

 (Guindy,
            Velachery,
            Thambaram,)

1 Answer 1

1

To determine if a value is found in an array, you use the IN operator.

[NSPredicate predicateWithFormat:@"TravelsName IN %@", array];
Sign up to request clarification or add additional context in comments.

6 Comments

thank you so much it working..i need to know more about NSPredicate.
Just wait until you finally understand SUBQUERY(). It opens up whole worlds :)
hi i have another doubt also in that i'm having boarding it's a array value means how to i filter it
Ask in a separate question or modify this one. I can't tell what you mean without an example.
The simplest thing to do is build a compound OR predicate, where each subpredicate uses IN. I'm sure there's a better way, but I'm too busy to work it out at this time.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.