-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Storage.swift
184 lines (136 loc) · 5.24 KB
/
Storage.swift
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import Foundation
/// `StoreKey` definition aka. `String`.
public typealias StoreKey = String
/// `Storage` protocol.
@StorageActor
public protocol Storage: StorageDelegate, Sendable {
/**
Adds the contents of the specified dictionary to the registration domain.
- Parameter defaults: The dictionary of keys and values you want to register.
*/
func register(defaults registration: [StoreKey: Any])
/**
Returns the generic value associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func value<V>(forKey key: StoreKey) -> V?
/**
Returns the `Decodable` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func decodable<D: Decodable>(forKey key: StoreKey) -> D?
/**
Returns the `StorageData` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func data<D: StorageData>(forKey key: StoreKey) -> D?
/**
Returns the `String` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func string(forKey key: StoreKey) -> String?
/**
Returns the `[Any]` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func array(forKey key: StoreKey) -> [Any]?
/**
Returns the `Set<AnyHashable>` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func set(forKey key: StoreKey) -> Set<AnyHashable>?
/**
Returns the `[String: Any]` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func dictionary(forKey key: StoreKey) -> [String: Any]?
/**
Returns the `[String]` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func stringArray(forKey key: StoreKey) -> [String]?
/**
Returns the `Int` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func integer(forKey key: StoreKey) -> Int
/**
Returns the `Float` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func float(forKey key: StoreKey) -> Float
/**
Returns the `Double` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func double(forKey key: StoreKey) -> Double
/**
Returns the `Bool` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func bool(forKey key: StoreKey) -> Bool
/**
Returns the `URL` associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
func url(forKey key: StoreKey) -> URL?
/**
Sets the value of the specified `StoreKey` to the specified `Int`.
- Parameter value: `Int` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set(_ value: Int, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified `Float`.
- Parameter value: `Float` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set(_ value: Float, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified `Double`.
- Parameter value: `Double` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set(_ value: Double, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified `Bool`.
- Parameter value: `Bool` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set(_ value: Bool, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified `URL`.
- Parameter url: `URL` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set(_ url: URL?, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified `String`.
- Parameter string: `String` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set(_ string: String, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified generic value.
- Parameter value: Generic value to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set<V>(_ value: V?, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified `Encodable`.
- Parameter encodable: `Encodable` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set(encodable: Encodable?, forKey key: StoreKey)
/**
Sets the value of the specified `StoreKey` to the specified `StorageData`.
- Parameter data: `StorageData` to store.
- Parameter key: The `StoreKey` with which to associate the value.
*/
func set<D: StorageData>(_ data: D?, forKey key: StoreKey)
/**
Removes the value of the specified `StoreKey`.
- Parameter key: The `StoreKey` whose value you want to remove.
*/
func remove(forKey key: StoreKey)
}