mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Implement NSCoding
This commit is contained in:
parent
36b209ff2e
commit
a46edf3643
1 changed files with 25 additions and 0 deletions
|
@ -26,6 +26,8 @@
|
||||||
#include <Foundation/NSMeasurement.h>
|
#include <Foundation/NSMeasurement.h>
|
||||||
#include <Foundation/NSUnit.h>
|
#include <Foundation/NSUnit.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
#include <Foundation/NSArchiver.h>
|
||||||
|
#include <Foundation/NSKeyedArchiver.h>
|
||||||
|
|
||||||
@implementation NSMeasurement
|
@implementation NSMeasurement
|
||||||
// Creating Measurements
|
// Creating Measurements
|
||||||
|
@ -122,10 +124,33 @@
|
||||||
// NSCoding
|
// NSCoding
|
||||||
- (void) encodeWithCoder: (NSCoder *)coder
|
- (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
|
- (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;
|
return self;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue