Skip to content

Instantly share code, notes, and snippets.

@rabinjoshi
Created June 18, 2011 15:13
Show Gist options
  • Save rabinjoshi/1033166 to your computer and use it in GitHub Desktop.
Save rabinjoshi/1033166 to your computer and use it in GitHub Desktop.
//
// main.m
// Archiving3
//
// Created by Rabin Joshi on 6/18/11.
// Copyright 2011 Techgene. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Foo.h"
#import "Bar.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
NSLog(@"Hello, World!");
//Unarchiving
NSMutableData *dataArea2;
NSKeyedUnarchiver *unarchiver;
Foo *myFoo2;
Bar *myBar2;
dataArea2 = [NSData dataWithContentsOfFile:@"/Users/rabinjoshi/Desktop/myArchive.plist"];
if (! dataArea2) {
NSLog (@"Can’t read back archive file!");
//Return (1);
}
unarchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData: dataArea2];
// Decode the objects we previously stored in the archive
myFoo2 = [unarchiver decodeObjectForKey: @"myFoo1"];
myBar2 = [unarchiver decodeObjectForKey: @"myBar1"];
[unarchiver finishDecoding];
[unarchiver release];
// Verify that the restore was successful
NSLog (@"%@ \n %i \n %g", [myFoo2 strVal], [myFoo2 intVal], [myFoo2 floatVal]);
NSLog (@"%@ \n %i \n %g", [myBar2 strVal], [myBar2 intVal], [myBar2 floatVal]);
[pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment