-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathExtensionBridge.swift
62 lines (49 loc) · 1.52 KB
/
ExtensionBridge.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
// ∅ 2025 lil org
import Foundation
struct ExtensionBridge {
private static let defaults = SharedDefaults.defaults
private static func key(id: Int) -> String {
return String(id)
}
static var defaultInfuraKeys: [String]? {
get {
return defaults?.array(forKey: "defaultInfuraKeys") as? [String]
}
set {
defaults?.set(newValue, forKey: "defaultInfuraKeys")
}
}
private static var initiatedRequests: Set<Int> {
get {
Set(defaults?.array(forKey: "initiatedRequests") as? [Int] ?? [])
}
set {
defaults?.set(Array(newValue), forKey: "initiatedRequests")
}
}
static func makeRequest(id: Int) {
initiatedRequests.insert(id)
}
static func hasRequest(id: Int) -> Bool {
if initiatedRequests.contains(id) {
removeRequest(id: id)
return true
} else {
return false
}
}
static func respond(response: ResponseToExtension) {
defaults?.set(response.json, forKey: key(id: response.id))
}
static func removeRequest(id: Int) {
initiatedRequests.remove(id)
}
static func removeResponse(id: Int) {
let key = key(id: id)
defaults?.removeObject(forKey: key)
}
static func getResponse(id: Int) -> [String: AnyHashable]? {
let key = key(id: id)
return defaults?.value(forKey: key) as? [String: AnyHashable]
}
}