• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Document based app problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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]
initForWritingWithMutableData: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]
initForReadingWithData: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.

References: 
 >Document based app problems (From: April Gendill <email@hidden>)
 >Re: Document based app problems (From: Shawn Erickson <email@hidden>)
 >Re: Document based app problems (From: April Gendill <email@hidden>)

  • Prev by Date: Re: NSPopUpButton trouble
  • Next by Date: Re: Core Foundation analog to NSArchiver?
  • Previous by thread: Re: Document based app problems
  • Next by thread: Re: Document based app problems
  • Index(es):
    • Date
    • Thread