Skip navigation.
 
mlRe: Hierarchal Archiving
FROM : j o a r
DATE : Tue Jan 28 21:25:32 2003

Implement a method to serialize & restore the objects to / from a
string:

+ (id) objectWithStringRepresentation:(NSString *) str;
- (NSString *) stringRepresentation

...and then:

- (void) saveDocumentDictionary:(NSDictionary *) docDict
toPath:(NSString *) docPath
{
   NSMutableDictionary *archiveDict = [NSMutableDictionary dictionary];

   NSEnumerator *enumerator = [docDict keyEnumerator];
   NSString *keyStr;
   while ((keyStr = [enumerator nextObject]))
   {
       id obj = [docDict objectForKey: keyStr];
       [archiveDict setObject: [obj stringRepresentation] forKey: keyStr];
   }

   [archiveDict writeToFile: docPath atomically: YES];
}

(Programmed in Mail, disclaimer, disclaimer, yada, yada....)

j o a r

On Tuesday, Jan 28, 2003, at 19:21 Europe/Stockholm, The Amazing Llama
wrote:

> I am programming a document that needs to save it's data to disk, like
> any good document.
>
> The data in question is a dictionary whose keys are names (NSStrings)
> and whose objects are a custom class I have coded, whose instances
> store arrays of arrays of numbers. How do I write this to disk? The
> options I know of are:
>
> use NSArchiver.
>     This has lots of drawbacks for future file formats, as well as
> ordering issues. I'd rather avoid it.
>
> use NSKeyedArchiver.
>     This is better than the above, but I can't figure out how to archive
> the array in a clean, object-oriented way; I cannot have each of my
> objects store using simple keys, because they all try to store using
> the same keys. I would have to subclass NSKeyedArchiver to provide
> some sort of context for each object, or have each of my custom
> instances make it's own NSKeyedArchiver, store it's data in that, and
> then encode the resulting NSData instead of itself. This would be a
> hassle and not clean at all, in my opinion.
>
> use NSDictionary's writeToFile:atomically:
>     This would be my favorite option, as it writes to clean, readable xml
> that doesn't use unique IDs to identify its own parts, but I can't
> figure out how to go about it. writeToFile:atomically will only store
> certain types, and appears to have no extensibility in this regard.
>
> Look at ~/Library/Safari/Bookmarks.plist to see what I'd like to be
> able to do; a simple array of objects, within which I can store the
> same keys over and over, without colliding into each other. Is there
> any good way of doing this?
>
> Seth A. Roby            The Amazing Llama < mail or AIM me at tallama at mac
> dot com>
> "Life is like an exploded clown. It's really funny until you figure
> out what just happened."
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.

_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlHierarchal Archiving The Amazing Llama Jan 28, 19:21
mlRe: Hierarchal Archiving j o a r Jan 28, 21:25
mlRe: Hierarchal Archiving Don Murta Jan 28, 22:57
mlHierarchal Archiving Lorenzo Puleo Jan 29, 00:57