我有一个包含更多词典的NSDictionary。最终字典的值(叶子)是包含一些数据的数组。每片叶子的深度都是未知的。
我试图编写递归函数来组合0级密钥子级的所有数组。
这是我到目前为止所拥有的:
- (NSArray *)getAllDictArrays:(NSDictionary *)dictionary WithKey:(NSString *)key
{
if ([[dictionary objectForKey:key] isKindOfClass:[NSArray class]]) {
// grab array and save for later or append to global array and return later
} else {
NSDictionary *newDict = [dictionary objectForKey:key];
NSString *newKey;
for (newKey in newDict.allKeys) {
//NSLog(@"Calling Key: %@", newKey);
[self getAllDictArrays:newDict WithKey:newKey];
}
}
return ???;
}