- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有NSMutableArray
,它存储NSDictionary
。考虑以下包含NSDictionary
的数组。
<__NSArrayM 0x7f9614847e60>(
{
"PARAMETER_KEY" = 1;
"PARAMETER_VALUE" = ALL;
},
{
"PARAMETER_KEY" = 2;
"PARAMETER_VALUE" = ABC;
},
{
"PARAMETER_KEY" = 3;
"PARAMETER_VALUE" = DEF;
},
{
"PARAMETER_KEY" = 4;
"PARAMETER_VALUE" = GHI;
},
{
"PARAMETER_KEY" = 5;
"PARAMETER_VALUE" = JKL;
}
)
NSDictionary
的索引。
int tag = (int)[listArray indexOfObject:dictionary];
PARAMETER_VALUE = GHI
并使用此值,我想将该字典索引查找到数组中。我不想使用for循环。我可以在没有for循环的情况下获取索引吗?
最佳答案
您可以像这样在category
上添加NSArray
(这也会进行类型安全检查;仅处理字典数组):
- (NSInteger)indexOfDictionaryWithKey:(NSString *)iKey andValue:(id)iValue {
NSUInteger index = [self indexOfObjectPassingTest:^BOOL(NSDictionary *dict, NSUInteger idx, BOOL *stop) {
if (![dict isKindOfClass:[NSDictionary class]]) {
*stop = YES;
return false;
}
return [dict[iKey] isEqual:iValue];
}];
return index;
}
indexOfDictionaryWithKey:andValue:
即可获取索引。
NSArray
中再添加一个类别:
- (NSDictionary *)dictionaryWithKey:(NSString *)iKey andValue:(id)iValue {
NSUInteger index = [self indexOfDictionaryWithKey:iKey andValue:iValue];
return (index == NSNotFound) ? nil : self[index];
}
关于ios - 查找存储在NSDictionary中的值的索引和存储在NSMutableArray中的NSDictionary的值的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33143836/
在 viewDidLoad 上,我的应用程序填充 NSMutableArray arrayOfHaiku,它是 NSDictionary 项的数组,如下所示: NSError *error; NS
我在 NSMutableArray 上是这样的: NSMutableArray *array = [NSMutableArray arrayWithObjects:@"0",@"0",@"0",@"0
我正在尝试设置我的 allArticlesArray 的内容,然后将附加对象附加到数组中。这是我的代码片段: [self.allArticlesArray setArray:newsArray]; [
我用 NSMutableArray 中的数据填充了 TableView ,一切正常。当我选择一个单元格(didSelectRowAtIndex)时,该项目将从数组中删除,正如它应该做的那样。现在我希望
我有一个 NSMutableArray 是我的代表,我也在我的一个 View Controller 中使用它。 所以在 viewDidLoad 我像这样制作我的 NSMutableArray 的可变副
我有 100 个元素的 NSMutableArray。 我想将“20 - 50”、“10 - 20”、“60 - 100”和 50 - 60. 元素加载到单独的 NSMutableArray 中,并将
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
我在尝试将字符串的 NSMutableArray 共享给另一个类时遇到了一些问题。我有一个 tableView,其中填充了 Strings,我想将其添加到 NSMutableArray。然后在另一个
正如我们所知,数组是一个连续的内存分配。那么 NSMutableArray 大小将如何增加。 最佳答案 C 数组确实使用连续内存,C++ std::vector 也是如此,但是 NSMutableAr
我需要对一个数组进行排序,里面有一个数组,像这样: NSMutableArray * array_example = [[NSMutableArray alloc] init]; [array_e
这看起来很简单,但我只是得到一个空数组。 我想获取一个按下的按钮,找到它旁边的所有按钮(参见代码中的注释),并将所有找到的按钮添加到另一个 NSMutableArray。 然后我想遍历该数组并对每个按
我正在尝试在另一个 NSMutableArray 中添加 NSMutableArray。但我想做的是嵌套数组。 我当前的代码是: NSMutableArray *array1 = [NSMutab
我有三个类,即DepartmentViewController、DepartmentRequest、Department。这就像我从 DepartmentViewcontroller 发出部门请求,并
我正在尝试将 NSMutableArray 存储在 NSMutableArray 中。所以 var all:NSMutableArray = NSMutableArray() let localArr
这一定是那些错误之一,您一直盯着代码看很长时间,以至于找不到错误。 我有这个代码块,我在其中循环遍历一个包含多个 NSMutableArray 的 NSMutableArray: // FoodVi
我有一个包含 50 个条目的 NSMutableArray - 有什么简单的方法可以将其分成 5 个 NSMutableArray,每个 10 个条目。 最佳答案 是的,要划分 NSMutableAr
我想将 NSMutableArray 的 addObject 放入 NSMutableArray 中,那么我如何快速实现这一点。并检索它,所以请帮助我,因为现在我正在快速学习。 间接说我要二维数组是指
好吧: 我有 NSMutableArray 1 我还有 NSMutableArray 2 我想从数组 1 中删除与数组 2 中的对象匹配的所有对象。 有什么想法吗? 最佳答案 我刚刚打开文档,打印 N
我正在尝试制作 NSMutableArray 的深拷贝,其对象是与此类似的自定义类的实例: @interface CustomParent : NSObject @property NSInteger
我知道你们可能会觉得这是一个重复的问题。但我对我的项目的这个问题搞砸了。 现在转到这个问题,我已经采取了NSMutableArray命名为 arr1包含字符串值,例如 @"34" , @"40"等等。
我是一名优秀的程序员,十分优秀!