Seems simple enough – I’m creating one master NSMutableDic and filling it with more of them.
What’s an easy way to access the contents of a dictionary like this?
Although this isn’t Python, perhaps something to the extent of ‘taskDict[4][‘assignedby’]’?
Here’s the code which works fine and dandy:
int counter = 0;
NSArray *cols = [GetProjectInfo getTaskColumns];
NSArray *rows = [GetProjectInfo fetchAll:projectName];
NSMutableDictionary *taskDict = [NSMutableDictionary dictionary];
NSMutableDictionary *localDict = [NSMutableDictionary dictionary];
for (int x=0; x < rows.count; x++) {
NSString *rowData = [rows objectAtIndex:x];
NSString *colData = [cols objectAtIndex:counter];
//Assign the values colData(key) and rowData(value) into localDict.
[localDict setValue:rowData forKey:colData];
counter ++;
if (counter >= cols.count) {
counter = 0;
//Add the whole localDict to the global dictionary (taskDict)
[taskDict setObject:localDict forKey:localDict];
//Reset the localDict so that we can populate it with the next set
[localDict removeAllObjects];
}
}
NSLog(@"%@",taskDict);
returns something to the extent of:
{
person = "Ryan";
assignedby = jfreund;
complete = False;
timeassigned = "15:35:00";
} = {
};
{
person = "Tim";
assignedby = klang;
complete = True;
timeassigned = "16:59:07";
} = {
};
Anybody care to throw some ideas this direction?
This doesn’t directly answer your question; but rather than store your object graph as nested dictionaries, could you instead use
NSObjectsubclasses to encapsulate your data so that you don’t have to traverse hierarchies of dictionaries? For example, (mind you, I know nothing about your application’s model layer…) could you break the conceptual model into Project and Task objects, e.g.And then Projects are, in turn, composed of Tasks:
It’s a more object-oriented way of structuring the application’s model layer. There’s nothing about this mechanism that would preclude you from serializing the data to a plist so long as your classes conform to the
NSCodingprotocol.