Re: selecting output format - NSKeyedArchiver
Re: selecting output format - NSKeyedArchiver
- Subject: Re: selecting output format - NSKeyedArchiver
- From: Scott Anguish <email@hidden>
- Date: Tue, 29 Oct 2002 16:51:17 -0500
On Tuesday, October 29, 2002, at 10:30 AM, email@hidden wrote:
Im trying to write an object to disk, but i get a warning that
`NSKeyedArchiver' does not respond to `archiveRootObject:toFile:'
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] init];
[archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
[archiver archiveRootObject:[[dataController sharedDataController]
theList] toFile:[sp filename]];
i guess you cant use a class method from an instance?
Nope..
Is there an easy method of selecting output format for an
NSKeyedArchiver
or should i subclass it and customise the class method.
it seems as if im doing something wrong here.
Instead of archiving the root object using that API, it might be a
better idea to encode it the normal way.. that way you could add
additional objects at the top level of the file for some future version
of the app (like a version number.. )
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutable
Data:data];
[archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
[archiver encodeObject:YOUROBJECTHERE
forKey:YOURKEYHERE];
[archiver finishEncoding];
[archiver release];
[data writeToFile:SOMEFILE atomically:YES]
[data release];
of course you could wrap this up into a category on NSKeyedArchiver
+archiveObject:withKey:toFile:asXML:
_______________________________________________
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.