gpt4 book ai didi

iphone - 组合 NSMutableSets 时出现问题

转载 作者:行者123 更新时间:2023-12-03 16:26:12 27 4
gpt4 key购买 nike

我有以下代码:

   NSMutableSet* localSet = [[NSMutableSet alloc] initWithArray:symbols];
NSMutableArray* fetchedSymbolsArray = [NSMutableArray array];

for (NSDictionary* symbol in fetchedSymbols) {
[fetchedSymbolsArray addObject:[NSDictionary dictionaryWithObject:[symbol valueForKey:@"symbol"] forKey:@"symbol"]];
}

NSMutableSet* serverSet = [[NSMutableSet alloc] initWithArray:fetchedSymbolsArray];

[localSet unionSet:serverSet];

for (NSDictionary* symbol in localSet) {
NSLog(@"%@",[symbol valueForKey:@"symbol"]);
}

我希望 serverSet 中的所有内容都位于 localSet 中。此代码没有反射(reflect)这一点。

如果不将任何重复项添加到 localSet 中也会更好。

编辑:这是我的日志:

2011-08-16 17:46:28.887 Stream[94612:207] YHOO
2011-08-16 17:46:28.887 Stream[94612:207] GOOG
2011-08-16 17:46:28.887 Stream[94612:207] INTC
2011-08-16 17:46:28.888 Stream[94612:207] BIDU
2011-08-16 17:46:28.888 Stream[94612:207] INTC
2011-08-16 17:46:28.888 Stream[94612:207] BIDU
2011-08-16 17:46:28.888 Stream[94612:207] AAPL
2011-08-16 17:46:28.888 Stream[94612:207] AAPL
2011-08-16 17:46:28.889 Stream[94612:207] AMD
2011-08-16 17:46:28.889 Stream[94612:207] GMCR

最佳答案

尝试[localSet unionSet:serverSet]

编辑

这里的代码仅使用符号而不是 NSDictionary:

NSArray *symbols = [NSArray arrayWithObjects:@"AAPL",@"GOOG",@"INTC",@"YHOO",nil];

NSArray *fetchedSymbols = [NSArray arrayWithObjects:@"AMD",@"BIDU",@"GOOG",@"GMCR",@"INTC",@"YHOO",nil];


NSMutableSet* localSet = [[NSMutableSet alloc] initWithArray:symbols];
NSMutableSet* serverSet = [[NSMutableSet alloc] initWithArray:fetchedSymbols];

[localSet unionSet:serverSet];

for (id symbol in localSet) {
NSLog(@"%@",symbol);
}

2011-08-16 18:25:22.107 so7086790[39810:a0f] YHOO
2011-08-16 18:25:22.116 so7086790[39810:a0f] AMD
2011-08-16 18:25:22.116 so7086790[39810:a0f] AAPL
2011-08-16 18:25:22.116 so7086790[39810:a0f] INTC
2011-08-16 18:25:22.117 so7086790[39810:a0f] GMCR
2011-08-16 18:25:22.117 so7086790[39810:a0f] GOOG
2011-08-16 18:25:22.118 so7086790[39810:a0f] BIDU

关于iphone - 组合 NSMutableSets 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7086790/

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