implement settings

This commit is contained in:
2026-01-27 02:39:24 +01:00
parent f45f7db10b
commit 5f05da552d
5 changed files with 124 additions and 19 deletions

View 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
}
}