NSOutlineView and NSKeyedArchiver
NSOutlineView and NSKeyedArchiver
- Subject: NSOutlineView and NSKeyedArchiver
- From: Ian McGregor <email@hidden>
- Date: Wed, 10 Dec 2003 07:49:41 -0800
I have a data source for an NSOutlineView modeled on the AppKit
DragNDropOutlineView example. I am having difficulty saving the
datasource in mydocument using NSKeyedArchiver and reloading it again.
My other objects are saving fine.
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSMutableData *data;
NSKeyedArchiver *archiver;
data = [NSMutableData data];
archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutable
Data:data];
[archiver encodeObject:assets_array forKey:@"Assets"];
[archiver encodeObject:groups_array forKey:@"Groups"];
//NSLog(@":: %@",[outlineDataSource outlineView:outlineView child:0
ofItem:nil]);
[archiver encodeObject:[outlineDataSource outlineView:outlineView
child:0 ofItem:nil] forKey:@"treeData"];
//[archiver encodeObject:outlineDataSource forKey:@"treeData"];
[archiver finishEncoding];
[archiver autorelease];
return data;
}
I have tried a few things as you can see. My datasource object is
outlineDatasource which is instantiated in IB with a connection from
MyDocument to it via: IBOutlet OutlineDatasource *outlineDataSource
I have edited OutlineDatasource, my "item" object and nearly every
other object in sight to comply with <NSCopying>.
Eg.
@interface OutlineDatasource : NSObject <NSCoding>
{
@private
IBOutlet NSOutlineView *outlineView;
IUAssetTreeNode *treeData;
NSArray *draggedNodes;
NSArray *iconImages;
}
etc...
@implementation OutlineDatasource
- (id)initWithCoder:(NSCoder *)decoder {
[super init];
treeData = [[decoder decodeObject] retain];
NSLog(@"decoding treeData %@",treeData);
draggedNodes = [[decoder decodeObject] retain];
iconImages = [[decoder decodeObject] retain];
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:treeData];
NSLog(@"encoding treeData %@",treeData);
[coder encodeObject:draggedNodes];
[coder encodeObject:iconImages];
}
etc...
Any ideas, examples, pointers appreciated!
Cheers,
Ian
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.