宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
//  RxMutableBox.swift
//  RxSwift
//
//  Created by Krunoslav Zaher on 5/22/15.
//  Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
 
#if os(Linux)
/// As Swift 5 was released, A patch to `Thread` for Linux
/// changed `threadDictionary` to a `NSMutableDictionary` instead of
/// a `Dictionary<String, Any>`: https://github.com/apple/swift-corelibs-foundation/pull/1762/files
///
/// This means that on Linux specifically, `RxMutableBox` must be a `NSObject`
/// or it won't be possible to store it in `Thread.threadDictionary`.
///
/// For more information, read the discussion at:
/// https://github.com/ReactiveX/RxSwift/issues/1911#issuecomment-479723298
import class Foundation.NSObject
 
/// Creates mutable reference wrapper for any type.
final class RxMutableBox<T>: NSObject {
    /// Wrapped value
    var value: T
 
    /// Creates reference wrapper for `value`.
    ///
    /// - parameter value: Value to wrap.
    init (_ value: T) {
        self.value = value
    }
}
#else
/// Creates mutable reference wrapper for any type.
final class RxMutableBox<T>: CustomDebugStringConvertible {
    /// Wrapped value
    var value: T
    
    /// Creates reference wrapper for `value`.
    ///
    /// - parameter value: Value to wrap.
    init (_ value: T) {
        self.value = value
    }
}
 
extension RxMutableBox {
    /// - returns: Box description.
    var debugDescription: String {
        return "MutatingBox(\(self.value))"
    }
}
#endif