-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUserDefaultsClient.swift
44 lines (37 loc) · 1.03 KB
/
UserDefaultsClient.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
import Foundation
public struct UserDefaultsClient {
public init(
saveValue: Operations.Save,
loadValue: Operations.Load,
removeValue: Operations.Remove
) {
self.saveValue = saveValue
self.loadValue = loadValue
self.removeValue = removeValue
}
public var saveValue: Operations.Save
public var loadValue: Operations.Load
public var removeValue: Operations.Remove
}
extension UserDefaultsClient {
public struct Key:
RawRepresentable,
ExpressibleByStringLiteral,
ExpressibleByStringInterpolation
{
public var rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
public init(stringLiteral value: String) {
self.init(rawValue: value)
}
public static func bundle(_ key: Key) -> Key {
return .bundle(.main, key)
}
public static func bundle(_ bundle: Bundle, _ key: Key) -> Key {
let prefix = bundle.bundleIdentifier.map { $0.appending(".") } ?? ""
return .init(rawValue: prefix.appending(key.rawValue))
}
}
}