@@ -13,58 +13,48 @@ import Foundation
13
13
14
14
/// An actor that manages a shared context using a dictionary.
15
15
public final class SharedContext {
16
- private var map : [ String : Any ] = [ : ]
17
- private var queue = DispatchQueue ( label: " shared.conext.queue " , attributes: . concurrent)
16
+ private var map : [ String : Any ]
17
+
18
+ /// Initializes the SharedContext with an empty dictionary or a pre-existing one.
19
+ ///
20
+ /// - Parameter map: A dictionary to initialize the context with. Defaults to an empty dictionary.
21
+ public init ( _ map: [ String : Any ] = [ : ] ) {
22
+ self . map = map
23
+ }
24
+
25
+ /// Sets a value for the given key in the shared context.
26
+ ///
27
+ /// - Parameters:
28
+ /// - key: The key for which to set the value.
29
+ /// - value: The value to set for the given key.
30
+ public func set( key: String , value: Any ) {
31
+ self . map [ key] = value
32
+ }
33
+
34
+ /// Retrieves the value for the given key from the shared context.
35
+ ///
36
+ /// - Parameter key: The key for which to get the value.
37
+ /// - Returns: The value associated with the key, or `nil` if the key does not exist.
38
+ public func get( key: String ) -> Any ? {
39
+ return self . map [ key]
18
40
19
- /// Initializes the SharedContext with an empty dictionary or a pre-existing one.
20
- ///
21
- /// - Parameter map: A dictionary to initialize the context with. Defaults to an empty dictionary.
22
- public init ( _ map: [ String : Any ] = [ : ] ) {
23
- queue. sync ( flags: . barrier) {
24
- self . map = map
25
- }
26
- }
41
+ }
42
+
43
+ /// Removes the value for the given key from the shared context.
44
+ ///
45
+ /// - Parameter key: The key for which to remove the value.
46
+ /// - Returns: The removed value, or `nil` if the key does not exist.
47
+ public func removeValue( forKey key: String ) -> Any ? {
48
+ self . map. removeValue ( forKey: key)
49
+ }
50
+
51
+ /// A Boolean value indicating whether the shared context is empty.
52
+ public var isEmpty : Bool {
53
+ return self . map. isEmpty
54
+ }
55
+
56
+ /// A namespace for key names to be added in an extension.
57
+ public enum Keys {
27
58
28
- /// Sets a value for the given key in the shared context.
29
- ///
30
- /// - Parameters:
31
- /// - key: The key for which to set the value.
32
- /// - value: The value to set for the given key.
33
- public func set( key: String , value: Any ) {
34
- queue. sync ( flags: . barrier) {
35
- self . map [ key] = value
36
- }
37
- }
38
-
39
- /// Retrieves the value for the given key from the shared context.
40
- ///
41
- /// - Parameter key: The key for which to get the value.
42
- /// - Returns: The value associated with the key, or `nil` if the key does not exist.
43
- public func get( key: String ) -> Any ? {
44
- queue. sync {
45
- return self . map [ key]
46
- }
47
- }
48
-
49
- /// Removes the value for the given key from the shared context.
50
- ///
51
- /// - Parameter key: The key for which to remove the value.
52
- /// - Returns: The removed value, or `nil` if the key does not exist.
53
- public func removeValue( forKey key: String ) -> Any ? {
54
- queue. sync ( flags: . barrier) {
55
- self . map. removeValue ( forKey: key)
56
- }
57
- }
58
-
59
- /// A Boolean value indicating whether the shared context is empty.
60
- public var isEmpty : Bool {
61
- queue. sync {
62
- return self . map. isEmpty
63
- }
64
- }
65
-
66
- /// A namespace for key names to be added in an extension.
67
- public enum Keys {
68
-
69
- }
59
+ }
70
60
}
0 commit comments