Implementation of copying and copy protocols for base class

This commit is contained in:
Gregory John Casamento 2019-10-02 00:24:46 -04:00
parent e95de25ea0
commit 4c51378c0c
2 changed files with 74 additions and 2 deletions

View file

@ -32,12 +32,22 @@
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST)
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
@interface NSUnit : NSObject
@interface NSUnit : NSObject <NSCopying, NSCoding>
{
NSString *_symbol;
}
+ (instancetype)new;
- (instancetype)init;
- (instancetype)initWithSymbol:(NSString *)symbol;
- (NSString *)symbol;
@end
#if defined(__cplusplus)
}
#endif

View file

@ -27,5 +27,67 @@
@implementation NSUnit
+ (instancetype)new
{
return [[self alloc] init];
}
- (instancetype)init
{
self = [super init];
if(self != nil)
{
ASSIGNCOPY(_symbol, @"");
}
return self;
}
- (instancetype)initWithSymbol:(NSString *)symbol
{
self = [super init];
if(self != nil)
{
ASSIGNCOPY(_symbol, symbol);
}
return self;
}
- (id) initWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
_symbol = [coder decodeObjectRorKey: @"symbol"];
}
else
{
_symbol = [coder decodeObject];
}
return self;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
[coder encodeObject: _symbol forKey: @"coder"];
}
else
{
[coder encodeObject: _symbol];
}
}
- (instancetype) copyWithZone: (NSZone *)zone
{
NSUnit *u = [[NSUnit allocWithZone: zone] initWithSymbol: [self symbol]];
return u;
}
- (NSString *)symbol
{
return _symbol;
}
@end