Why is NSKeyedArchiver's performance so poor? Size doubles against NSArchiver.
I encode NSMutableArray objects with the following line
BOOL result = [NSArchiver archiveRootObject:self.appDataObject.materias toFile:archivePath];
NSMutableArray contains custom objects that have corresponding encodeWithCoder and initWithCoder
-(void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject: _fileName]; [aCoder encodeObject: _categoria]; [aCoder encodeObject: _materia]; [aCoder encodeObject: _nombre]; [aCoder encodeObject: _position]; [aCoder encodeValueOfObjCType:@encode(BOOL) at:&_favorite]; } -(id)initWithCoder:(NSCoder *)aDecoder { if (self=[super init]) { [self setFileName:[aDecoder decodeObject]]; [self setCategoria:[aDecoder decodeObject]]; [self setMateria:[aDecoder decodeObject]]; [self setNombre:[aDecoder decodeObject]]; [self setPosition:[aDecoder decodeObject]]; [aDecoder decodeValueOfObjCType:@encode(BOOL) at:&_favorite]; } return self; }
It works fine, as it saves the file correctly, and then I can unlock it. They comprise about 3,000 objects, and the output file is 900 KB
The problem occurs when I change my archiving string to:
BOOL result = [NSKeyedArchiver archiveRootObject:self.appDataObject.materias toFile:archivePath];
Everything magically works BUT , the file size more than doubles to 2 MB !
Why am I asking about this? because I am developing an iOS application and therefore losing support for NSArchiver.
source share