You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1005 B
37 lines
1005 B
![]()
2 years ago
|
//
|
||
|
// Platform.Darwin.swift
|
||
|
// Platform
|
||
|
//
|
||
|
// Created by Krunoslav Zaher on 12/29/15.
|
||
|
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
|
||
|
|
||
|
import Darwin
|
||
|
import class Foundation.Thread
|
||
|
import protocol Foundation.NSCopying
|
||
|
|
||
|
extension Thread {
|
||
|
static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: NSCopying) {
|
||
|
let currentThread = Thread.current
|
||
|
let threadDictionary = currentThread.threadDictionary
|
||
|
|
||
|
if let newValue = value {
|
||
|
threadDictionary[key] = newValue
|
||
|
}
|
||
|
else {
|
||
|
threadDictionary[key] = nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static func getThreadLocalStorageValueForKey<T>(_ key: NSCopying) -> T? {
|
||
|
let currentThread = Thread.current
|
||
|
let threadDictionary = currentThread.threadDictionary
|
||
|
|
||
|
return threadDictionary[key] as? T
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|