簡體   English   中英

iOS字典的過濾器數組基於值而不是鍵

[英]iOS filter array of dictionary base on value and not the key

我有這樣的字典數組:

Array: (
 {
customerUS= {
 DisplayName = "level";
 InternalName = "Number 2";
 NumberValue = 1;
 },
 customerCAN= {
 DisplayName = "PurchaseAmount";
 InternalName = "Number 1";
 NumberValue = 3500;
 };
}
)

我想根據特定值而不是鍵來過濾字典。 例如,我希望所有字典的值都在3500的任何鍵上。任何機構都知道我該怎么做?

非常感謝您的幫助。

嘗試使用謂詞格式,例如:

@"%@ IN SELF", testValue

當您過濾數組時,每個數組都將針對IN運行。 當你通過IN一本字典它使用字典的值。

你也可以使用

-keysOfEntriesPassingTest:

NSDictionary。 像這樣傳遞一個塊:

for(NSDictionary *myDictionary in myArray){ 
    NSSet *resultSet = [myDictionary keysOfEntriesPassingTest:^(id key, id object, BOOL *stop) {
        //assuming that 3500 is an int, otherwise use appropriate condition.
        if([[NSNumber numberWithInt:object] isEqual:[NSNumber numberWithInt:3500]]){
            return YES;
        }else{
            return NO;
        }
     }];
    if (resultSet.count>0){
        //do whatever to myDictionary
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM