CocoaDev

Edit AllPages

Before I go and reinvent the wheel, does anyone have any code to parse a .plist file and display it in a NSOutlineView? I need to do something similar to PropertyListEditor.

Here is something to start with… I did not write it to the end, because I am almost as lazy as you! :)

void add_entry (id src, NSMutableArray* dst, NSString* name) { NSMutableDictionary* entry = [NSMutableDictionary dictionaryWithObjectsAndKeys: name, @”label”, src, @”object”, nil];

if([src isKindOfClass:[NSArray class]]) { NSMutableArray* children = [NSMutableArray array]; for(unsigned i = 0; i != [src count]; ++i) add_entry([src objectAtIndex:i], children, [NSString stringWithFormat:@”%ud”, i]); [entry setObject:children forKey:@”children”]; } else if([src isKindOfClass:[NSDictionary class]]) { NSMutableArray* children = [NSMutableArray array]; NSEnumerator* enumerator = [src keyEnumerator]; while(id key = [enumerator nextObject]) add_entry([src objectForKey:key], children, key); [entry setObject:children forKey:@”children”]; } else … { … } [dst addObject:entry]; }

// load data in init

// data source methods