1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-22 13:11:55 +03:00
vimr/VimR/ToolPrefData.swift

49 lines
1.2 KiB
Swift
Raw Normal View History

2016-11-18 20:54:14 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
protocol StandardPrefData {
init?(dict: [String: Any])
func dict() -> [String: Any]
}
struct ToolPrefData: StandardPrefData {
fileprivate static let identifier = "identifier"
fileprivate static let isVisible = "isVisible"
fileprivate static let dimension = "dimension"
let identifier: ToolIdentifier
let isVisible: Bool
let dimension: Float
init(identifier: ToolIdentifier, isVisible: Bool, dimension: Float) {
self.identifier = identifier
self.isVisible = isVisible
self.dimension = dimension
}
func dict() -> [String: Any] {
return [
ToolPrefData.identifier: self.identifier,
ToolPrefData.isVisible: self.isVisible,
ToolPrefData.dimension: self.dimension,
]
}
init?(dict: [String: Any]) {
guard let identifier = dict[ToolPrefData.identifier] as? ToolIdentifier,
let isVisible = dict[ToolPrefData.isVisible] as? Bool,
let dimension = dict[ToolPrefData.dimension] as? Float
else {
return nil
}
self.init(identifier: identifier, isVisible: isVisible, dimension: dimension)
}
}