2

I have a class Persistent, which needs to be archivable, but can change its name. NSKeyedArchiver provides +setClassName: method to use custom class name during archiving and unarchiving. Can I perform class-name mapping in +load method? Are there any gotchas?

@interface Persistent : NSObject <NSCoding>
@end
@implementation
+ (void)load {
   [NSKeyedArchiver setClassName:@"class" forClass:self];
}
...
@end
Roman B.
  • 3,598
  • 1
  • 25
  • 21
  • You need more courage than me to implement +load. Courage isn't necessarily a good thing for a programmer. +load or +initialize is something I'd keep my hands off. One reason is the fun that you will have when moving to Swift :-) – gnasher729 Oct 08 '16 at 16:16
  • Related: [+\[NSObject load\] and +initialize: what do they do?](http://stackoverflow.com/q/13326435) and see also a relevant tidbit from bbum here: http://stackoverflow.com/a/4671741/603977 – jscs Oct 08 '16 at 19:48

0 Answers0