在一个数组中映射多个数组
Mapping multiple Arrays in one Array
我有两个数组,一个包含项目列表的数组:
一个包含字符串对象的数组
和一个数组对象
NSArray * a=[1,2,nil];
NSArray * b=[[abc],[def],[ijk],[lmp], nil];
我想 return 数组,方法是将数组 "a" 对象“1”映射到数组 "b",对象为“[abc],[def]”
和数组 "a" 对象“2”到数组 "b" 和对象“[ijk],[lmp]”
我知道我可以在 NSDictionary
中实现,但我想 return NSArray
而不是 NSDictionary
.
或任何替代方法。
我觉得更多的是数据结构方面的知识?
我看到你的模式是增加两个索引。
那么,这是你想要的东西吗?
NSMutableArray *object;
NSUInteger indexOfA = [a indexOfObject:@1]; // get the index of the object from A
for (NSUInteger index = 0; index < 2; index++) {
[object addObject:b[indexOfA * 2 + index]];
}
然后,你可以从b中拉出你想要的东西。
我有两个数组,一个包含项目列表的数组: 一个包含字符串对象的数组 和一个数组对象
NSArray * a=[1,2,nil];
NSArray * b=[[abc],[def],[ijk],[lmp], nil];
我想 return 数组,方法是将数组 "a" 对象“1”映射到数组 "b",对象为“[abc],[def]” 和数组 "a" 对象“2”到数组 "b" 和对象“[ijk],[lmp]”
我知道我可以在 NSDictionary
中实现,但我想 return NSArray
而不是 NSDictionary
.
或任何替代方法。
我觉得更多的是数据结构方面的知识? 我看到你的模式是增加两个索引。 那么,这是你想要的东西吗?
NSMutableArray *object;
NSUInteger indexOfA = [a indexOfObject:@1]; // get the index of the object from A
for (NSUInteger index = 0; index < 2; index++) {
[object addObject:b[indexOfA * 2 + index]];
}
然后,你可以从b中拉出你想要的东西。