1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Model/Accounts/AccountsBridge.swift

38 lines
939 B
Swift
Raw Normal View History

2021-10-28 02:41:38 +05:30
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,
"name": value.name ?? "",
"apiURL": value.url,
"sid": value.sid
]
}
func deserialize(_ object: Serializable?) -> Value? {
guard
let object = object,
let id = object["id"],
let instanceID = object["instanceID"],
let url = object["apiURL"],
let sid = object["sid"]
else {
return nil
}
let name = object["name"] ?? ""
return Account(id: id, instanceID: instanceID, name: name, url: url, sid: sid)
}
}