使用谓词iOS SDK从Dictionary数组过滤图像

时间:2018-08-02 07:50:14

标签: objective-c

我有一个字典数组,您能告诉我如何根据字典键过滤这些图像吗?

{ test1 = "<UIImage: 0x6000002a10e0> size {1668, 2500} orientation 0 scale 1.000000"; },
{ test2 = "<UIImage: 0x6040002a0e40> size {4288, 2848} orientation 0 scale 1.000000"; }

1 个答案:

答案 0 :(得分:0)

您可能想要这样的东西吗?

NSArray *imageDicts = @[@{@"test1": [UIImage imageNamed:@"cat"]}, @{@"test2": [UIImage imageNamed:@"cat"]}, @{@"test3": @"string, should be ignored"}];
NSMutableArray *images = [NSMutableArray array];
for (NSDictionary *info in imageDicts) {
    for (NSString *key in [info allKeys]) {
        id obj = info[key];
        if ([obj isKindOfClass:[UIImage class]]) {
            [images addObject:obj];
        }
    }
}
NSLog(@"%@", images);

输出:

TestProject[15709:21109977] (
    "<UIImage: 0x60c0000a5460>, {1200, 1199}",
    "<UIImage: 0x60c0000a5760>, {1200, 1199}"
)