Browse Source

IOSAD-49 adds thread wrapper

IOSAD-49
buff 5 years ago
parent
commit
7fee1f1157
3 changed files with 81 additions and 0 deletions
  1. +6
    -0
      pEpObjCAdapter.xcodeproj/project.pbxproj
  2. +21
    -0
      pEpObjCAdapter/PEPCopyableThread.h
  3. +54
    -0
      pEpObjCAdapter/PEPCopyableThread.m

+ 6
- 0
pEpObjCAdapter.xcodeproj/project.pbxproj View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1508AEAF1F8792AC001D5230 /* PEPCopyableThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 1508AEAE1F8792AC001D5230 /* PEPCopyableThread.m */; };
43209B3D1ECC2DA7007E7E2E /* NSArray+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B271ECC2ACD007E7E2E /* NSArray+Extension.m */; };
43209B3E1ECC2DAB007E7E2E /* PEPCSVScanner.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B291ECC2ACD007E7E2E /* PEPCSVScanner.m */; };
43209B3F1ECC2DB0007E7E2E /* PEPLanguage.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B2B1ECC2ACD007E7E2E /* PEPLanguage.m */; };
@ -103,6 +104,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1508AEAD1F8792AC001D5230 /* PEPCopyableThread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPCopyableThread.h; sourceTree = "<group>"; };
1508AEAE1F8792AC001D5230 /* PEPCopyableThread.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPCopyableThread.m; sourceTree = "<group>"; };
352988AA1AEF964100FA7E2E /* libpEpObjCAdapter.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libpEpObjCAdapter.a; sourceTree = BUILT_PRODUCTS_DIR; };
35FB0ABB1B57F97E00377032 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
35FB0ABD1B57F99D00377032 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
@ -220,6 +223,8 @@
43209B351ECC2ACD007E7E2E /* PEPSession.m */,
43D27DE41F5DA78700795687 /* NSDictionary+Extension.h */,
43D27DE51F5DA7B700795687 /* NSDictionary+Extension.m */,
1508AEAD1F8792AC001D5230 /* PEPCopyableThread.h */,
1508AEAE1F8792AC001D5230 /* PEPCopyableThread.m */,
);
path = pEpObjCAdapter;
sourceTree = "<group>";
@ -401,6 +406,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1508AEAF1F8792AC001D5230 /* PEPCopyableThread.m in Sources */,
43209B411ECC2DB8007E7E2E /* PEPObjCAdapter.m in Sources */,
43D27DE61F5DA7B700795687 /* NSDictionary+Extension.m in Sources */,
43209B431ECC2DC0007E7E2E /* PEPSession.m in Sources */,


+ 21
- 0
pEpObjCAdapter/PEPCopyableThread.h View File

@ -0,0 +1,21 @@
//
// PEPCopyableThread.h
// pEpObjCAdapter
//
// Created by Andreas Buff on 06.10.17.
// Copyright © 2017 pp. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
Wrapper around NSThread. Created solely to be able to use a thread as key in
a NSDIctionary (e.g. conform to NSCopying).
*/
@interface PEPCopyableThread : NSObject<NSCopying>
@property (atomic, strong, readonly) NSThread *thread;
- (instancetype)initWithThread:(NSThread * _Nonnull)thread;
@end

+ 54
- 0
pEpObjCAdapter/PEPCopyableThread.m View File

@ -0,0 +1,54 @@
//
// PEPCopyableThread.m
// pEpObjCAdapter
//
// Created by Andreas Buff on 06.10.17.
// Copyright © 2017 pp. All rights reserved.
//
#import "PEPCopyableThread.h"
@interface PEPCopyableThread()
@property (atomic, strong) NSThread *thread;
@end
@implementation PEPCopyableThread
#pragma mark - Life Cycle
- (instancetype)init
{
NSAssert(false, @"Please call initWithThread instead");
return nil;
}
- (instancetype)initWithThread:(NSThread * _Nonnull)thread
{
self = [super init];
if (self) {
self.thread = thread;
}
return self;
}
- (BOOL)isEqual:(PEPCopyableThread *)object
{
return [self.thread isEqual:object.thread];
}
- (NSUInteger)hash
{
return [NSString stringWithFormat:@"%@", self.thread].hash;
}
#pragma mark - NSCopying
- (instancetype)copyWithZone:(NSZone *)zone
{
PEPCopyableThread *copy = [[PEPCopyableThread alloc] initWithThread:self.thread];
return copy;
}
@end

Loading…
Cancel
Save