如何过滤 NsmutableArray 中的多个字符串

how to filter multiple string in NsmutableArray

大家好,我的项目中有一个 NSMutableArray,它包含一个字典值,这里我过滤了一个字符串,但现在我想过滤这个数组中的多个字符串,下面是我的数组值

(
        {
        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";
    }
)

在此我过滤了一个字符串,如卧铺巴士

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

然后我用 Sleeper 和 AC 这样的两个字符串过滤

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

这也很好用,但现在我想像拥有数组和字符串一样进行过滤

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

我试过这段代码 这里的 arr 是上面提到的数组

 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);
        }

帮帮我..

已更新

(
        {
        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";
    }
)

在这个数组中我也在这个数组中登机我想在登机数组上过滤也意味着 BusAC 是 A/c 登机是

 (Guindy,
            Velachery,
            Thambaram,)

要确定是否在数组中找到某个值,请使用 IN 运算符。

[NSPredicate predicateWithFormat:@"TravelsName IN %@", array];