yattee/Model/Accounts/AccountsBridge.swift

40 lines
1.1 KiB
Swift
Raw Normal View History

2021-10-27 21:11:38 +00:00
import Defaults
import Foundation
struct AccountsBridge: Defaults.Bridge {
typealias Value = Account
typealias Serializable = [String: String]
func serialize(_ value: Value?) -> Serializable? {
guard let value = value else {
return nil
}
return [
"id": value.id,
"instanceID": value.instanceID ?? "",
2021-10-27 21:11:38 +00:00
"name": value.name ?? "",
"apiURL": value.url,
"username": value.username,
"password": value.password ?? ""
2021-10-27 21:11:38 +00:00
]
}
func deserialize(_ object: Serializable?) -> Value? {
guard
let object = object,
let id = object["id"],
let instanceID = object["instanceID"],
let url = object["apiURL"],
let username = object["username"]
2021-10-27 21:11:38 +00:00
else {
return nil
}
let name = object["name"] ?? ""
let password = object["password"]
2021-10-27 21:11:38 +00:00
return Account(id: id, instanceID: instanceID, name: name, url: url, username: username, password: password)
2021-10-27 21:11:38 +00:00
}
}