2024-04-13 22:44:43 +00:00
|
|
|
//
|
|
|
|
// PreferenceKey.swift
|
|
|
|
// TuskerPreferences
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 4/12/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public protocol PreferenceKey {
|
|
|
|
associatedtype Value: Codable
|
|
|
|
|
|
|
|
static var defaultValue: Value { get }
|
|
|
|
|
|
|
|
static func didSet(in store: PreferenceStore, newValue: Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PreferenceKey {
|
2024-04-16 02:30:20 +00:00
|
|
|
public static func didSet(in store: PreferenceStore, newValue: Value) {}
|
2024-04-13 22:44:43 +00:00
|
|
|
}
|
2024-04-15 14:37:02 +00:00
|
|
|
|
|
|
|
protocol MigratablePreferenceKey: PreferenceKey where Value: Equatable {
|
|
|
|
static func shouldMigrate(oldValue: Value) -> Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
extension MigratablePreferenceKey {
|
|
|
|
static func shouldMigrate(oldValue: Value) -> Bool {
|
|
|
|
oldValue != defaultValue
|
|
|
|
}
|
|
|
|
}
|
2024-04-15 14:50:08 +00:00
|
|
|
|
|
|
|
protocol CustomCodablePreferenceKey: PreferenceKey {
|
|
|
|
static func encode(value: Value, to encoder: any Encoder) throws
|
|
|
|
static func decode(from decoder: any Decoder) throws -> Value?
|
|
|
|
}
|