0

I'm trying to archive a tree of objects using NSKeyedArchiver. All nodes in the tree support NSCoding, but I don't have access to the source code, so I can't change anything. However, I'd like to include an additional NSString with some of the nodes during encoding. When unarchiving, I'd like to get that string (if available) and do some additional setup depending on what that string is.

How could I do this in an elegant way? I thought about substituting a subclass when encoding, implementing the additional encoding in the subclass. And make the subclass' initWithCoder: return an instance of the superclass, properly initialized and setup. The problem with this is, that I might have "real" subclasses of the node classes in my tree. And if such a subclass is encoded, the substitution wouldn't work. Or at least I don't see how.

Currently I'm looking into subclassing NSKeyedArchiver, but I'm not sure where I could inject anything or if this is a good approach at all.

DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • 3
    Instead of subclassing why don't use NSKeyedArchiver delegate to decorate the behaviour of `NSKeyedArchiver` to get the work done? Probably this `– archiver:willEncodeObject:` method could be of help. – HepaKKes Jun 24 '13 at 22:39
  • I thought that was just a notification to keep track of the progress, but not a way to influence the process. I'll try that, thanks. – DrummerB Jun 24 '13 at 22:52

0 Answers0