I currently am working on a grouped tableView. I have it working but want to change my incoming arrays into dictionaries to provide more useful information in tableview. The DictionaryHolder has all different keys which is the name, it contains a dictionary with "mainTheme" key some of these mainKeys match and I would like to compile those matching dictionary into array and then back into a new dictionary with new key "subThemes" which is the array of dictionary set contains matches of "mainTheme"... Ive hit a wall and don't know how to approach this which methods would be the fastest because at times there could be a lot of dictionaries being created and sorted. Any help would be greatly appreciated!
-(NSMutableArray*)themesDictFromThemesPlists:(NSMutableArray*)allThemesonDevice{
NSMutableDictionary *compiledThemesDictionaryHolder = [[NSMutableDictionary alloc]init];
NSMutableArray *returnedDict = [[NSMutableArray alloc]init];
NSMutableDictionary *mainThemeCompiled = [[NSMutableDictionary alloc]init];
NSMutableDictionary *themePlistDict = nil;
NSString *packageName= nil;
NSString*fullPlistStr = nil;
NSString *themeStringToDeconstruct = nil;
//create dictionary for each theme
NSMutableArray *allPckgNames = [[NSMutableArray alloc]init];
for (NSString *actualName in allThemesonDevice) {
themeStringToDeconstruct = actualName;
if ([themeStringToDeconstruct hasSuffix:@".theme"]) {
themeStringToDeconstruct = [themeStringToDeconstruct stringByReplacingOccurrencesOfString:@".theme" withString:@""];
}
themeStringToDeconstruct = [themeStringToDeconstruct stringByReplacingOccurrencesOfString:@"_" withString:@" "];
NSArray *theWords = [themeStringToDeconstruct componentsSeparatedByString:@" "];
NSString *nameWithoutTags = [theWords objectAtIndex:0];
//NSLog (@"ICONOMATIC OBJECT AT INDEX 0 %@",newName);
fullPlistStr = [NSString stringWithFormat:@"/Library/Themes/%@/Info.plist",actualName];
themePlistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPlistStr];
packageName = [themePlistDict objectForKey:@"PackageName"];
//NSLog (@"ThemePlistDict: %@",themePlistDict);
//NSLog (@"ICONOMATIC Actual Name : %@ PackageName: %@",actualName,packageName);
if (packageName) {
NSMutableDictionary *compiledTheme = [[NSMutableDictionary alloc]init];
[compiledTheme setValue:actualName forKey:@"fullThemeName"];
[compiledTheme setValue:nameWithoutTags forKey:@"themeName"];
[compiledTheme setValue:packageName forKey:@"mainTheme"];
//can add more icons
if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/Library/Themes/%@/icon.png",actualName]]) {
[compiledTheme setValue:[NSString stringWithFormat:@"/Library/Themes/%@/icon.png",actualName] forKey:@"icon1"];
}
NSLog (@"Iconomatic ADD compiledTheme %@ ",compiledTheme);
[compiledThemesDictionaryHolder setValue:compiledTheme forKey:actualName];
//[compiledThemesDictionaryHolder addObject:compiledTheme];
[allPckgNames addObject:packageName];
}
}
NSLog (@"Iconomatic compiledThemesDictionaryHolder %@ ",compiledThemesDictionaryHolder);
NSLog (@"Iconomatic ALLPckgs: %@",allPckgNames);
/*create Main Dictionary for each package
This is where Ive hit a wall. I need to determine which dictionaries have matching
"mainTheme" keysValues and compile into array of dictionaries to store in new dictionary
(mainThemeCompiled) which will be added into returnDict which is a array that populates the
tableview by keys*/
//NSSet or descriptorByKeys I don't know how to approach this
//NSMutableArray *tempStorage = [[NSMutableArray alloc]init];
for (NSDictionary *themeDict in compiledThemesDictionaryHolder) {
NSLog (@"Iconomatic themeDict: %@",themeDict);
[mainThemeCompiled setValue:themeDict forKey:@"package"];
}
NSLog(@"Iconomatic compiledThemesDictionaryHolder %@",returnedDict);
return returnedDict;
}
Iconomatic compiledThemesDictionaryHolder {
"Bohemic NOIR alt.theme" = {
fullThemeName = "Bohemic NOIR alt.theme";
icon1 = "/Library/Themes/Bohemic NOIR alt.theme/icon.png";
mainTheme = BohemicNOIR;
themeName = Bohemic;
};
"Bohemic NOIR badges.theme" = {
fullThemeName = "Bohemic NOIR badges.theme";
icon1 = "/Library/Themes/Bohemic NOIR badges.theme/icon.png";
mainTheme = BohemicNOIR;
themeName = Bohemic;
};
"Bohemic NOIR iPad calendar.theme" = {
fullThemeName = "Bohemic NOIR iPad calendar.theme";
icon1 = "/Library/Themes/Bohemic NOIR iPad calendar.theme/icon.png";
mainTheme = BohemicNOIR;
themeName = Bohemic;
};
"Bohemic NOIR mask" = {
fullThemeName = "Bohemic NOIR mask";
icon1 = "/Library/Themes/Bohemic NOIR mask/icon.png";
mainTheme = BohemicNOIR;
themeName = Bohemic;
};
Ok so here was my overall solution. The main issue was determining the available matching objects in array of dictionary and was solved by using indexesOfObjectsPassingTest and enumerateIndexesUsingBlock
OutPut of Main Theme is now
and Final is: