pEpObjCAdapter/PEPCopyableThread.m
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 17 May 2018 09:33:33 +0200
changeset 616 9e50cc7cd612
parent 278 08ef7a7ad650
permissions -rw-r--r--
IOSAD-93 consistently using precomposedStringWithCanonicalMapping, stringWithUTF8String
andreas@260
     1
//
andreas@260
     2
//  PEPCopyableThread.m
andreas@260
     3
//  pEpObjCAdapter
andreas@260
     4
//
andreas@260
     5
//  Created by Andreas Buff on 06.10.17.
andreas@260
     6
//  Copyright © 2017 p≡p. All rights reserved.
andreas@260
     7
//
andreas@260
     8
andreas@260
     9
#import "PEPCopyableThread.h"
andreas@260
    10
andreas@260
    11
@interface PEPCopyableThread()
andreas@260
    12
@property (atomic, strong) NSThread *thread;
andreas@260
    13
@end
andreas@260
    14
andreas@260
    15
@implementation PEPCopyableThread
andreas@260
    16
andreas@262
    17
- (BOOL)isFinished
andreas@262
    18
{
andreas@262
    19
    return self.thread.isFinished || !self.thread;
andreas@262
    20
}
andreas@262
    21
andreas@262
    22
- (void)cancel
andreas@262
    23
{
andreas@262
    24
    [self.thread cancel];
andreas@262
    25
}
andreas@262
    26
andreas@260
    27
#pragma mark - Life Cycle
andreas@260
    28
andreas@260
    29
- (instancetype)init
andreas@260
    30
{
andreas@260
    31
    NSAssert(false, @"Please call initWithThread instead");
andreas@260
    32
    return nil;
andreas@260
    33
}
andreas@260
    34
andreas@262
    35
- (instancetype)initWithThread:(NSThread * _Nonnull)thread;
andreas@260
    36
{
andreas@260
    37
    self = [super init];
andreas@260
    38
    if (self) {
andreas@260
    39
        self.thread = thread;
andreas@260
    40
    }
andreas@260
    41
    return self;
andreas@260
    42
}
andreas@260
    43
andreas@278
    44
- (void)dealloc
andreas@278
    45
{
andreas@278
    46
    self.thread = nil;
andreas@278
    47
}
andreas@278
    48
andreas@262
    49
#pragma mark - NSObject
andreas@262
    50
andreas@260
    51
- (BOOL)isEqual:(PEPCopyableThread *)object
andreas@260
    52
{
andreas@260
    53
    return [self.thread isEqual:object.thread];
andreas@260
    54
}
andreas@260
    55
andreas@260
    56
- (NSUInteger)hash
andreas@260
    57
{
andreas@260
    58
    return [NSString stringWithFormat:@"%@", self.thread].hash;
andreas@260
    59
}
andreas@260
    60
andreas@261
    61
- (NSString *)description
andreas@261
    62
{
andreas@261
    63
    return [self.thread description];
andreas@261
    64
}
andreas@261
    65
andreas@260
    66
#pragma mark - NSCopying
andreas@260
    67
andreas@260
    68
- (instancetype)copyWithZone:(NSZone *)zone
andreas@260
    69
{
andreas@260
    70
    PEPCopyableThread *copy = [[PEPCopyableThread alloc] initWithThread:self.thread];
andreas@260
    71
    return copy;
andreas@260
    72
}
andreas@260
    73
andreas@260
    74
@end