枚举 NSMutableDictionary 时难以根据键排除对象
我很困惑。我有一个带有嵌套字典的 NSMutableDictionary,我正在枚举它以在嵌套字典中创建特定键值的数组,但我想排除两个“键”。
如果我排除一个键,我就可以做到这一点,但是一旦我尝试使用“||”或者我的 If 语句中的运算符它停止工作,只是将所有对象添加到我的新数组中,而不是所有对象,而是我试图过滤掉的两个对象。
我的枚举逻辑:
for (NSString *key in self.myMutDictionary) {
theBool = [key isEqualToString:@"First"];
NSLog(@"Is key = to First? %@", (theBool ? @"YES" : @"NO"));
if ((![key isEqualToString:@"First"]) || (![key isEqualToString:@"Second"])) {
newDict = [self.myMutDictionary objectForKey:key];
[self.filteredArray addObject:[newDict objectForKey:@"Third"]];
NSLog(@"Filtered Array: %@", self.filteredArray);
}}
感谢您的帮助!
I'm stumped. I have an NSMutableDictionary w/ nested dictionaries that I am enumerating through to create an Array of a particular key value in a nested dictionary, but I want to exlude two "keys".
I am able to do it if I exclude one key, but as soon as I try to use the "||" or operator in my If statement it stops working and just adds all the objects to my new array, instead of all objects, but the two I'm trying to filter out.
My enumerating logic:
for (NSString *key in self.myMutDictionary) {
theBool = [key isEqualToString:@"First"];
NSLog(@"Is key = to First? %@", (theBool ? @"YES" : @"NO"));
if ((![key isEqualToString:@"First"]) || (![key isEqualToString:@"Second"])) {
newDict = [self.myMutDictionary objectForKey:key];
[self.filteredArray addObject:[newDict objectForKey:@"Third"]];
NSLog(@"Filtered Array: %@", self.filteredArray);
}}
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改变||到&&
如果它不是第一个也不是第二个,则将其包括在内。
您想要排除 (A OR B),但您要反转整个表达式来选择要包含的内容,因此应该是 (!A AND !B)
Change || to &&
If it's not First AND not Second then include it.
You want to exclude (A OR B), but you're inverting the whole expression to select what to include, so it should be (!A AND !B)