我有兩個plist
文件,我用它們作爲數據源在我的應用程序中創建NSArray
和NSDictionaries
。我需要將兩個NSArray/NSDictionaries結合在一起
我想要的CSV文件的輸出看起來像:
exerciseName, muscleGroup, description
Barbell Curl, Biceps, This is a bicep exercise
的問題是,我需要首先將兩個NSDictionaries我有。一個有exerciseName和muscleName,另一個有exerciseDescription。但我需要爲每個練習對象提供一個包含所有3個鍵的字典數組。
我用下面的代碼來構建主NSMutableArray
if (muscleArray == nil)
{
NSString *path = [[NSBundle mainBundle]pathForResource:@"data" ofType:@"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.muscleArray = rootLevel;
}
NSMutableArray *arrayForSearching = [NSMutableArray array];
for (NSDictionary *muscleDict in self.muscleArray)
for (NSDictionary *excerciseDict in [muscleDict objectForKey:@"exercises"])
[arrayForSearching addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[excerciseDict objectForKey:@"exerciseName"], @"exerciseName",
[muscleDict objectForKey:@"muscleName"], @"muscleName", nil]];
self.exerciseArray = arrayForSearching;
我用下面的代碼來構建具有exerciseDescription關鍵
NSString *exerciseNameString =self.exerciseName;
NSString *path = [[NSBundle mainBundle] pathForResource:@"ExerciseDescriptions" ofType:@"plist"];
NSDictionary *exerciseDescription = [NSDictionary dictionaryWithContentsOfFile:path];
NSString *description = [exerciseDescription objectForKey:exerciseNameString];
我不清楚你的問題是什麼。 – ThomasW