Re: Document based app problems
Re: Document based app problems
- Subject: Re: Document based app problems
- From: Shawn Erickson <email@hidden>
- Date: Sun, 4 Jan 2004 09:26:05 -0800
On Jan 3, 2004, at 10:19 PM, April Gendill wrote:
>
I was using the built in stubs when you start a doc based app in
>
xcode.
>
Basically I just turned the entire thing into a dictionary. Not to
>
hard. two objects to add too it is all. And saved it to disk
>
then simply restore the dictionary.
>
resotredDictionary = [someString propertyList]
>
someDict setDictionary:retoredDictionary
The following is an example of how it can be done (using the new keyed
archiver), I am using this code in one of my projects. Note that the
items being stored are dictionaries (NSDictionary) which may contain
other dictionaries and arrays. The collections contain a mix of
NSStrings and NSNumbers.
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSLog(@"MGTestResultsDocument dataRepresentationOfType");
NSMutableData* data = [NSMutableData data];
NSKeyedArchiver* archiver = [[[NSKeyedArchiver alloc]
initForWritingWithMutable
Data:data] autorelease];
[archiver encodeObject:[self syncedPreferences]
forKey:MGPreferencesFileKey];
[archiver encodeObject:[self cleanResults:results]
forKey:MGResultsFileKey];
[archiver finishEncoding];
return data;
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
NSLog(@"MGTestResultsDocument loadDataRepresentation");
NSKeyedUnarchiver* unarchiver = [[[NSKeyedUnarchiver alloc]
initForReadingWith
Data:data] autorelease];
[self setResults:[self localizeResults:[unarchiver
decodeObjectForKey:MGResultsFileKey]]];
[self setPreferences:[unarchiver
decodeObjectForKey:MGPreferencesFileKey]];
loadedFromFile = YES;
return YES;
}
-Shawn
_______________________________________________
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.