gpt4 book ai didi

ios - 查看 NSDictionary 键是否在另一个 NSArray 中

转载 作者:行者123 更新时间:2023-11-28 19:00:55 25 4
gpt4 key购买 nike

Database (
{
to = (NSString *)
from = (NSString *)
subject = (NSString *)
uid = int
body = (NSString *)
}, { ...
)

Downloaded (
{
to = (NSString *)
from = (NSString *)
subject = (NSString *)
uid = int
body = (null)
}, { ...
)

我立即从我的数据库中提取并加载一个包含大约 200 个 NSDictionay 对象的 NSArray 到我的 UITableView 中,然后我下载一个 相同结构 NSDictionary 但没有正文的 NSArray

问:我如何通过匹配所有 200 个已下载的 NSDictionary 来查看它是否已经在我的数据库 NSArray 中键:“uid”?

最佳答案

这应该可以解决问题:

NSArray *arrayOfNew = [arrayDownload filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"NOT (uid IN %@)", [arrayDataBase valueForKey:@"uid"]];

用这个样本数据测试过,如果有人想测试的话:

NSDictionary *dictionary0 = @{@"to":@"0",@"from":@"0",@"uid":@(0), @"body":@"0"};
NSDictionary *dictionary1 = @{@"to":@"1",@"from":@"1",@"uid":@(1), @"body":@"0"};
NSDictionary *dictionary2 = @{@"to":@"2",@"from":@"2",@"uid":@(2), @"body":@"0"};
NSDictionary *dictionary3 = @{@"to":@"3",@"from":@"3",@"uid":@(3), @"body":@"0"};

NSDictionary *dictionary4 = @{@"to":@"4",@"from":@"4",@"uid":@(2)};
NSDictionary *dictionary5 = @{@"to":@"5",@"from":@"5",@"uid":@(5)};

NSArray *arrayDataBase = @[dictionary0, dictionary1, dictionary2, dictionary3];
NSArray *arrayDownload = @[dictionary4, dictionary5];

//So the dictionary4 shouldn't be kept, and dictionary5 should be kept.
NSArray *arrayNew = [arrayDownload filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"NOT (uid IN %@)", [arrayDataBase valueForKey:@"uid"]]];
NSLog(@"arrayNew: %@", arrayNew);

输出:

arrayNew: (
{
from = 5;
to = 5;
uid = 5;
}

关于ios - 查看 NSDictionary 键是否在另一个 NSArray 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25890567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com