- 세트 엔진(수축→이완×횟수, 중단=미기록) iOS·워치 공용, 완주만 records.json 저장 - 첫 화면 시작 버튼 + 세팅(시간·횟수·진동 패턴)/설정(테마) 시트, 아래 스와이프 통계 - 통계: 하루(시간대별)/주간/월간 꺾은선, 달력 기준↔롤링(지난 7일·30일) 전환 - Live Activity(수축/이완·n/총·카운트다운), 백그라운드 무음 오디오로 타이머·진동 유지 - 단축어 '케겔 운동 시작', 워치 앱(즉시 시작·워치 전용 진동·physical-therapy 세션·기록 폰 병합) - 하루 다님 팔레트 계승(라이트/다크/시스템), 앱 아이콘 SVG→PNG 등록 - 검증: Debug·Release·워치 빌드 그린, 시뮬 QA 10장(26·18.5·워치 46/40mm), 완주·기록 경로 확인 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
57 lines
1.6 KiB
Swift
57 lines
1.6 KiB
Swift
//
|
|
// SessionRecord.swift
|
|
// Keging
|
|
//
|
|
// 완주한 세트 기록 — 중단한 세트는 저장하지 않는다 (CLAUDE.md §3.1)
|
|
//
|
|
|
|
import Foundation
|
|
import Combine
|
|
|
|
nonisolated struct SessionRecord: Codable, Identifiable, Equatable {
|
|
var id: UUID = UUID()
|
|
var startedAt: Date
|
|
var reps: Int
|
|
var contractSeconds: Int
|
|
var relaxSeconds: Int
|
|
}
|
|
|
|
@MainActor
|
|
final class RecordStore: ObservableObject {
|
|
static let shared = RecordStore()
|
|
|
|
@Published private(set) var records: [SessionRecord] = []
|
|
|
|
private var fileURL: URL { AppGroup.containerURL.appendingPathComponent("records.json") }
|
|
|
|
private init() { load() }
|
|
|
|
func load() {
|
|
guard let data = try? Data(contentsOf: fileURL),
|
|
let saved = try? JSONDecoder().decode([SessionRecord].self, from: data) else { return }
|
|
records = saved.sorted { $0.startedAt < $1.startedAt }
|
|
}
|
|
|
|
/// 중복(id) 병합 안전 — 워치에서 넘어온 기록도 이 경로로 합류
|
|
func append(_ record: SessionRecord) {
|
|
guard !records.contains(where: { $0.id == record.id }) else { return }
|
|
records.append(record)
|
|
records.sort { $0.startedAt < $1.startedAt }
|
|
save()
|
|
}
|
|
|
|
private func save() {
|
|
if let data = try? JSONEncoder().encode(records) {
|
|
try? data.write(to: fileURL, options: .atomic)
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
/// 검증 시드 전용 — 전체 교체
|
|
func _replaceAll(_ newRecords: [SessionRecord]) {
|
|
records = newRecords.sorted { $0.startedAt < $1.startedAt }
|
|
save()
|
|
}
|
|
#endif
|
|
}
|