0

Edit (2012/10/22): Restating this question in hopefully clearer terms.

Essentially, what I'm looking for is some NSCoder that can (un)archive between multiple locations. Some of the encoded objects primitives should be saved in location A while others should be saved in specified location B, etc.

For example, suppose we have a class with something like this:

@interface SomeClass
{
   NSString *ivar1;
   NSString *ivar2;
   NSString *ivar3;

   SomeClass *ivarZ;
}

...

@end

Somewhere we have an instance:

SomeClass *someObject;

What I want to do is something like the following on saving:

NSData *prefDat = [KeyedMultiArchiver archiveRootObject:someObject
                                       withPartitionKey:@"DataForNSUserDefaults"];
NSData *permDat = [KeyedMultiArchiver archiveRootObject:someObject
                                       withPartitionKey:@"DataForPermanentStorage"];
/* save prefDat to NSUserDefaults */;
/* save permDat to some appropriate NSURL */;

And then on unarchiving:

SomeClass *anotherObject = [SomeClass new];

NSData *prefDat = /* get from NSUserDefaults */;
NSData *permDat = /* get from appropriate NSURL */;

[KeyedMultiUnarchiver unarchiveData:prefDat
                         intoObject:anotherObject
                   withPartitionKey:@"DataForNSUserDefaults"];

[KeyedMultiUnarchiver unarchiveData:permDat
                         intoObject:anotherObject
                   withPartitionKey:@"DataForPermanentStorage"];

Where ivar1s might get saved to NSUserDefaults and ivar2s, ivar3s to disk somewhere.

I'll probably end up coding my own solution for this, but if you guys come up with any brilliant alternatives please let me know!

Will post final product.

Kara
  • 6,115
  • 16
  • 50
  • 57
Ncat
  • 417
  • 3
  • 10
  • I think you need to provide a little more detail about your structure. Is it a top level dict with mutable data and immutable data below it, or is the mutable data scattered around your immutable data structure? – Gordon Dove Jul 31 '12 at 09:14
  • It's at least 3 levels deep. Each object in each layer may have one of or both immutable and mutable data. From the global point of view, there is no systematic split between mutable and immutable properties; each class in the hierarchy decides for itself. I'm hoping to have the data serialization logic centralized as much as possible--would prefer to keep individual classes saving and loading their individual data or anything of that sort. – Ncat Jul 31 '12 at 09:35
  • Unfortunately, just after posting this question, the project became temporarily stopped, so I haven't been able to fix it yet. However, one (desperate) solution I thought of was to rewrite the serialization code to use Core Data instead. I'm really hoping to avoid this, so any suggestions are much appreciated. – Ncat Aug 06 '12 at 02:34
  • This project just got restarted. The reason for wanting this kind of behavior is that some of the ivars in my objects are expected to change semi-frequently while others are expected to not change at all once loaded. – Ncat Oct 22 '12 at 04:28

1 Answers1

0

Well, here's the solution I ended up coming up with:

https://github.com/xelxebar/BWPartitioning

Instead of subclassing NSCoder, this is purely a custom framework. The repository above is an XCode project and should run just out of the box. Comments are sparse and it's very alpha, but there's a bit of an explanation on it's intended usage pattern.

Feel free to use this however you can and/or ask any questions. Feedback is appreciated.

Cheers!

Ncat
  • 417
  • 3
  • 10