Tusker/Packages/TuskerPreferences/Sources/TuskerPreferences/Keys/AdvancedKeys.swift

29 lines
851 B
Swift
Raw Normal View History

2024-04-13 22:44:43 +00:00
//
// AdvancedKeys.swift
// TuskerPreferences
//
// Created by Shadowfacts on 4/13/24.
//
import Foundation
import Pachyderm
2024-04-15 14:37:02 +00:00
struct StatusContentTypeKey: MigratablePreferenceKey {
2024-04-13 22:44:43 +00:00
static var defaultValue: StatusContentType { .plain }
}
struct FeatureFlagsKey: MigratablePreferenceKey, CustomCodablePreferenceKey {
2024-04-13 22:44:43 +00:00
static var defaultValue: Set<FeatureFlag> { [] }
static func encode(value: Set<FeatureFlag>, to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(value.map(\.rawValue))
}
static func decode(from decoder: any Decoder) throws -> Set<FeatureFlag>? {
let container = try decoder.singleValueContainer()
let names = try container.decode([String].self)
return Set(names.compactMap(FeatureFlag.init(rawValue:)))
}
2024-04-13 22:44:43 +00:00
}