Re: NSArchiver
Re: NSArchiver
- Subject: Re: NSArchiver
- From: Brian Webster <email@hidden>
- Date: Sat, 11 Aug 2001 12:34:40 -0500
On Saturday, August 11, 2001, at 12:15 AM, cocoa-dev-
email@hidden wrote:
<code snipped>
This does not work however... I am not sure why but the compiler says
that NSArchiver does not respond to archiveRootObject... I checked the
doco and perhaps I do not understand how to use the + methods in each
class. I understand that + methods are class methods and not instance
methods?
When you call a class method, you send the message to the class
object rather than one of the instances of the class. You do
this by putting the name of the class in the method call rather
than a variable. So what you want is:
[NSArchiver archiveRootObject:tempObject toFile:@"/MyPath/3dObject"];
This is basically a shorthand for:
NSMutableData *archivedData = [[NSMutableData alloc] init];
NSArchiver *myArchiver = [[NSArchiver alloc]
initWithMutable
Data:archivedData];
[myArchiver encodeRootObject:tempObj]; //puts the data into archivedData
[archivedData writeToFile:@"/MyPath/3dObject" atomically:YES];
//writes the data to disk
[myArchiver release];
[archivedData release];
--
Brian Webster
email@hidden
http://www.owlnet.rice.edu/~bwebster