implement settings
This commit is contained in:
33
MultiChrono/AppSettings.swift
Normal file
33
MultiChrono/AppSettings.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// AppSettings.swift
|
||||
// MultiChrono
|
||||
//
|
||||
// Created by Beatrice Dellacà on 27/01/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
enum TimeFormat: String, CaseIterable, Codable {
|
||||
case millis = "Millis (00:00.000)"
|
||||
case cents = "Cents (00:00.00)"
|
||||
case tenths = "Tenths (00:00.0)"
|
||||
case seconds = "Seconds (00:00)"
|
||||
|
||||
var displayName: String { self.rawValue }
|
||||
}
|
||||
|
||||
class AppSettings: ObservableObject {
|
||||
static let shared = AppSettings()
|
||||
|
||||
@Published var timeFormat: TimeFormat {
|
||||
didSet {
|
||||
UserDefaults.standard.set(timeFormat.rawValue, forKey: "timeFormat")
|
||||
}
|
||||
}
|
||||
|
||||
private init() {
|
||||
let savedFormat = UserDefaults.standard.string(forKey: "timeFormat") ?? TimeFormat.tenths.rawValue
|
||||
self.timeFormat = TimeFormat(rawValue: savedFormat) ?? .tenths
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user