Implement real-time sync between iOS and Apple Watch apps using WatchConnectivity framework. This replaces reliance on CloudKit which doesn't work reliably in simulators. - Add WatchConnectivityManager to both iOS and Watch targets - Sync workouts, splits, exercises, and logs between devices - Update iOS views to trigger sync on data changes - Add onChange observer to ExerciseView for live progress updates - Configure App Groups for shared container storage - Add Watch app views: WorkoutLogsView, WorkoutLogListView, ExerciseProgressView
54 lines
1.4 KiB
Swift
54 lines
1.4 KiB
Swift
//
|
|
// NotesEditView.swift
|
|
// Workouts
|
|
//
|
|
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
struct NotesEditView: View {
|
|
@Environment(\.managedObjectContext) private var viewContext
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@ObservedObject var workoutLog: WorkoutLog
|
|
|
|
@State private var notesText: String = ""
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
Form {
|
|
Section {
|
|
TextEditor(text: $notesText)
|
|
.frame(minHeight: 200)
|
|
}
|
|
}
|
|
.navigationTitle("Edit Notes")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Cancel") {
|
|
dismiss()
|
|
}
|
|
}
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
Button("Save") {
|
|
saveChanges()
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
notesText = workoutLog.notes ?? ""
|
|
}
|
|
}
|
|
}
|
|
|
|
private func saveChanges() {
|
|
workoutLog.notes = notesText
|
|
try? viewContext.save()
|
|
WatchConnectivityManager.shared.syncAllData()
|
|
}
|
|
}
|