如何在目标c中搜索字符串数组?

时间:2014-06-06 08:58:37

标签: ios objective-c arrays nsmutablearray

Mydocument =         (
                        {
                "allow_signoff" = N;
                "chart_no" = PT00027045;
                "checked_note" = "";
                "doc_path" = "20130227\\imsgo_ad.jpg";
                "doc_type" = 3;
                "document_subcat" = "CONSULTATION REPORT";
                firstname = Pangchia;
                "forwardto_emp" =                 (
                    "Andrews, Engelyn",
                    "Anup12, Gau12",
                    "Anup12, Gauri12",
                    "Atienza, Marivic",
                    "Birdsong, Rovonia",
                    "Bliatout, Bobby"
                );
                "forwardto_title" =                 (
                    Administrator,
                    Biller,
                    CEO,
                    Counselor,
                    CPHW,
                    "Front Desk",
                    "Medical Assistant",
                    "Nurse Practitioner"
                );

我从网络服务获得此回复。现在我将来自forwardto_emp的数据存储到NSMutableArray中。但是,当我使用该数组时,我的应用程序崩溃了。我无法对其进行计数或对数组使用objectAtIndex方法。

1 个答案:

答案 0 :(得分:1)

这里我正在编写简单的代码,用于如何通过NSPredicate从数组中搜索值。

NSPredicate *predicateSearch = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", putValueForSearch]; // Here in your case you need to write value of array that you want to search
NSArray *resultSearchArray = [myArrayName filteredArrayUsingPredicate:predicateSearch];
NSLog(@"%@", resultSearchArray); // "myArrayName" is array that your want to search value from it.

根据您的要求更改上述代码。