NSPredicate on NSDictionary

╄→гoц情女王★ 提交于 2019-12-03 07:32:04

Do you mean that bandsArray is an array of dictionaries? If so, and assuming each dictionary has a name key, you should be able to change the predicate to something like @"SELF.name beginswith[c] %@".

If, on the other hand, bandsArray is actually a dictionary itself, maybe you want to do [[bandsArray allKeys] filteredArrayUsingPredicate...].

#import <Foundation/Foundation.h>
// clang -framework Foundation Siegfried.m 
    int
main() {
    NSArray *arr = @[
        @{@"1" : @"Fafner"},
        @{@"1" : @"Fasolt"}
    ];
    NSPredicate *p = [NSPredicate predicateWithFormat: @"SELF['1'] CONTAINS 'e'"];
    NSArray *res = [arr filteredArrayUsingPredicate:p];
    NSLog(@"Siegfried %@", res);
    return 0;
}
Bruno Fuster

Sorry, I didnt notice you had a NSArray of NSDictionaries.

Read this thread: Using NSPredicate to filter an NSArray based on NSDictionary keys

When you use NSDictionary, you should check by its Key... I'm not sure you're using the right approach!

I would do something like: @implementation Word : NSObect { NSString *title; }

then I would create a NSArray of Words and filter on them with: @"title beginswith[c] %@"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!