mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +00:00
40 lines
1.0 KiB
Swift
40 lines
1.0 KiB
Swift
import Defaults
|
|
import Foundation
|
|
|
|
struct AccountsBridge: Defaults.Bridge {
|
|
typealias Value = Account
|
|
typealias Serializable = [String: String]
|
|
|
|
func serialize(_ value: Value?) -> Serializable? {
|
|
guard let value else {
|
|
return nil
|
|
}
|
|
|
|
return [
|
|
"id": value.id,
|
|
"instanceID": value.instanceID ?? "",
|
|
"name": value.name,
|
|
"apiURL": value.urlString,
|
|
"username": value.username,
|
|
"password": value.password ?? ""
|
|
]
|
|
}
|
|
|
|
func deserialize(_ object: Serializable?) -> Value? {
|
|
guard
|
|
let object,
|
|
let id = object["id"],
|
|
let instanceID = object["instanceID"],
|
|
let url = object["apiURL"],
|
|
let username = object["username"]
|
|
else {
|
|
return nil
|
|
}
|
|
|
|
let name = object["name"] ?? ""
|
|
let password = object["password"]
|
|
|
|
return Account(id: id, instanceID: instanceID, name: name, urlString: url, username: username, password: password)
|
|
}
|
|
}
|