mirror of
https://github.com/lil-org/tokenary.git
synced 2025-01-08 06:36:33 +03:00
28 lines
749 B
Swift
28 lines
749 B
Swift
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
struct ExtensionBridge {
|
|
|
|
private static let defaults = UserDefaults(suiteName: "XWNXDSM6BU.ink.encrypted")
|
|
|
|
private static func key(id: Int) -> String {
|
|
return String(id)
|
|
}
|
|
|
|
static func respond(id: Int, response: ResponseToExtension) {
|
|
defaults?.setCodable(response, forKey: key(id: id))
|
|
}
|
|
|
|
static func getResponse(id: Int) -> ResponseToExtension? {
|
|
let key = key(id: id)
|
|
if let response = defaults?.codableValue(type: ResponseToExtension.self, forKey: key) {
|
|
defaults?.removeObject(forKey: key)
|
|
return response
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
}
|