Implement NSCoding

This commit is contained in:
Gregory John Casamento 2019-10-11 08:58:14 -04:00
parent 36b209ff2e
commit a46edf3643

View file

@ -26,6 +26,8 @@
#include <Foundation/NSMeasurement.h>
#include <Foundation/NSUnit.h>
#include <Foundation/NSException.h>
#include <Foundation/NSArchiver.h>
#include <Foundation/NSKeyedArchiver.h>
@implementation NSMeasurement
// Creating Measurements
@ -122,10 +124,33 @@
// NSCoding
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
[coder encodeObject: _unit forKey: @"unit"];
[coder encodeDouble: _doubleValue forKey: @"doubleValue"];
}
else
{
[coder encodeObject: _unit];
[coder encodeValueOfObjCType: @encode(double) at: &_doubleValue];
}
}
- (id) initWithCoder: (NSCoder *)coder
{
if((self = [super init]) != nil)
{
if([coder allowsKeyedCoding])
{
_unit = [coder decodeObjectForKey: @"unit"];
_doubleValue = [coder decodeDoubleForKey: @"doubleValue"];
}
else
{
_unit = [coder decodeObject];
[coder decodeValueOfObjCType: @encode(double) at: &_doubleValue];
}
}
return self;
}
@end