RxSwift/Platform/Platform.Darwin.swift
Keith Smiley a1a2f00c7a Remove scoped imports for library evolution
In order to support `-enable-library-evolution` and `swiftinteface`
files, we have to use non-scoped imports. I've filed an upstream bug to
track this https://bugs.swift.org/browse/SR-11782

This is a step towards https://github.com/ReactiveX/RxSwift/issues/2026
2020-10-06 20:36:28 +03:00

36 lines
951 B
Swift

//
// 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 Foundation
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