Skip to content

Instantly share code, notes, and snippets.

@liyanage
Created November 20, 2009 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liyanage/239246 to your computer and use it in GitHub Desktop.
Save liyanage/239246 to your computer and use it in GitHub Desktop.
// LDFLAGS='-framework Foundation' make archivertest
#import <Foundation/Foundation.h>
typedef enum Foo {
Foo1 = 0UL,
Foo2 = 1,
Foo3 = 2
} FooType;
typedef enum Bar {
Bar1 = 0x0000UL,
Bar2 = 0x0001,
Bar3 = 0x0002
} BarType;
int main (int argc, const char * argv[]) {
FooType a = Foo2;
FooType b = Foo1;
NSString *testa = @"foo";
NSString *testb = nil;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableData *data = [NSMutableData data];
NSArchiver *archiver = [[[NSArchiver alloc] initForWritingWithMutableData:data] autorelease];
// [archiver encodeValueOfObjCType:@encode(BarType) at:&a];
[archiver encodeValueOfObjCType:@encode(FooType) at:&a];
[archiver encodeObject:testa];
NSUnarchiver *unarchiver = [[[NSUnarchiver alloc] initForReadingWithData:data] autorelease];
[unarchiver decodeValueOfObjCType:@encode(unsigned long) at:&b];
// [unarchiver decodeValueOfObjCType:@encode(FooType) at:&b];
testb = [unarchiver decodeObject];
NSLog(@"%d %d %@ %@", a, b, testa, testb);
[pool release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment