mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
New file.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@823 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ab2ed86ac1
commit
7f261d0848
1 changed files with 49 additions and 0 deletions
49
Testing/nsarchiver.m
Normal file
49
Testing/nsarchiver.m
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* A demonstration of writing and reading with NSArchiver */
|
||||
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include <Foundation/NSUtilities.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
id set;
|
||||
id arp;
|
||||
|
||||
arp = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/* Create a Set of int's */
|
||||
set = [[NSSet alloc] initWithObjects:
|
||||
@"apple", @"banana", @"carrot", @"dal", @"escarole", @"fava", nil];
|
||||
|
||||
/* Display the set */
|
||||
printf("Writing:\n");
|
||||
{
|
||||
id o, e = [set objectEnumerator];
|
||||
while ((o = [e nextObject]))
|
||||
printf("%@\n", o);
|
||||
}
|
||||
|
||||
/* Write it to a file */
|
||||
[NSArchiver archiveRootObject: set toFile: @"./nsarchiver.dat"];
|
||||
|
||||
/* Release the object that was coded */
|
||||
[set release];
|
||||
|
||||
/* Read it back in from the file */
|
||||
set = [NSArchiver unarchiveObjectWithFile: @"./nsarchiver.dat"];
|
||||
|
||||
/* Display what we read, to make sure it matches what we wrote */
|
||||
printf("\nReading:\n");
|
||||
{
|
||||
id o, e = [set objectEnumerator];
|
||||
while (o = [e nextObject])
|
||||
printf("%@\n", o);
|
||||
}
|
||||
|
||||
/* Do the autorelease. */
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in a new issue