diff --git a/OCKSample.xcodeproj/project.pbxproj b/OCKSample.xcodeproj/project.pbxproj index b539b27..4ae9eb9 100644 --- a/OCKSample.xcodeproj/project.pbxproj +++ b/OCKSample.xcodeproj/project.pbxproj @@ -1245,7 +1245,7 @@ repositoryURL = "https://github.com/cbaker6/CareKit.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = "3.0.0-beta.10"; + minimumVersion = "3.0.0-beta.12"; }; }; 918FDEAD271B3F8F0045A0EF /* XCRemoteSwiftPackageReference "ParseCareKit" */ = { diff --git a/OCKSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/OCKSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9fb4ebb..fb27912 100644 --- a/OCKSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/OCKSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/cbaker6/CareKit.git", "state" : { - "revision" : "075d600052f168d49b542444577cf20033eb9666", - "version" : "3.0.0-beta.10" + "revision" : "671cfa7bc608f5ed985aebef5ebd2b135b7e5a3c", + "version" : "3.0.0-beta.12" } }, { diff --git a/OCKSample/Main/Care/CareView.swift b/OCKSample/Main/Care/CareView.swift index e3d39c5..a51ba70 100644 --- a/OCKSample/Main/Care/CareView.swift +++ b/OCKSample/Main/Care/CareView.swift @@ -15,14 +15,10 @@ import SwiftUI import UIKit struct CareView: UIViewControllerRepresentable { - private static var query: OCKEventQuery { - var query = OCKEventQuery(for: Date()) - query.taskIDs = [TaskID.steps] - return query - } + @Environment(\.appDelegate) private var appDelegate @Environment(\.careStore) private var careStore - @CareStoreFetchRequest(query: query) private var events + @CareStoreFetchRequest(query: query()) private var events func makeUIViewController(context: Context) -> some UIViewController { let viewController = createViewController() @@ -31,8 +27,10 @@ struct CareView: UIViewControllerRepresentable { return navigationController } - func updateUIViewController(_ uiViewController: UIViewControllerType, - context: Context) { + func updateUIViewController( + _ uiViewController: UIViewControllerType, + context: Context + ) { guard let navigationController = uiViewController as? UINavigationController, let careViewController = navigationController.viewControllers.first as? CareViewController else { Logger.feed.error("CareView should have been a UINavigationController") @@ -48,8 +46,16 @@ struct CareView: UIViewControllerRepresentable { } func createViewController() -> UIViewController { - CareViewController(store: careStore, - events: events) + CareViewController( + store: careStore, + events: events + ) + } + + static func query() -> OCKEventQuery { + var query = OCKEventQuery(for: Date()) + query.taskIDs = [TaskID.steps] + return query } } diff --git a/OCKSample/Main/Care/CareViewController.swift b/OCKSample/Main/Care/CareViewController.swift index 3b92364..31ffa29 100644 --- a/OCKSample/Main/Care/CareViewController.swift +++ b/OCKSample/Main/Care/CareViewController.swift @@ -50,11 +50,13 @@ class CareViewController: OCKDailyPageViewController { /// /// - Parameter store: The store from which to query the tasks. /// - Parameter computeProgress: Used to compute the combined progress for a series of CareKit events. - init(store: OCKAnyStoreProtocol, - events: CareStoreFetchedResults? = nil, - computeProgress: @escaping (OCKAnyEvent) -> CareTaskProgress = { event in - event.computeProgress(by: .checkingOutcomeExists) - }) { + init( + store: OCKAnyStoreProtocol, + events: CareStoreFetchedResults? = nil, + computeProgress: @escaping (OCKAnyEvent) -> CareTaskProgress = { event in + event.computeProgress(by: .checkingOutcomeExists) + } + ) { super.init(store: store, computeProgress: computeProgress) self.events = events } @@ -147,8 +149,11 @@ class CareViewController: OCKDailyPageViewController { This will be called each time the selected date changes. Use this as an opportunity to rebuild the content shown to the user. */ - override func dailyPageViewController(_ dailyPageViewController: OCKDailyPageViewController, - prepare listViewController: OCKListViewController, for date: Date) { + override func dailyPageViewController( + _ dailyPageViewController: OCKDailyPageViewController, + prepare listViewController: OCKListViewController, + for date: Date + ) { Task { do { let tasks = try await fetchTasks(on: date) @@ -205,8 +210,10 @@ class CareViewController: OCKDailyPageViewController { events?.last(where: { $0.result.task.id == taskId }) } - private func taskViewController(for task: OCKAnyTask, - on date: Date) -> [UIViewController]? { + private func taskViewController( + for task: OCKAnyTask, + on date: Date + ) -> [UIViewController]? { var query = OCKEventQuery(for: Date()) query.taskIDs = [task.id] @@ -216,8 +223,11 @@ class CareViewController: OCKDailyPageViewController { guard let event = getStoreFetchRequestEvent(for: task.id) else { return nil } - let view = NumericProgressTaskView<_NumericProgressTaskViewHeader>(event: event, numberFormatter: .none) - .careKitStyle(CustomStylerKey.defaultValue) + let view = NumericProgressTaskView<_NumericProgressTaskViewHeader>( + event: event, + numberFormatter: .none + ) + .careKitStyle(CustomStylerKey.defaultValue) return [view.formattedHostingController()] diff --git a/OCKSample/Main/Profile/ProfileView.swift b/OCKSample/Main/Profile/ProfileView.swift index 928ddbd..eadcb8a 100644 --- a/OCKSample/Main/Profile/ProfileView.swift +++ b/OCKSample/Main/Profile/ProfileView.swift @@ -13,8 +13,8 @@ import os.log import SwiftUI struct ProfileView: View { - private static var query = OCKPatientQuery(for: Date()) - @CareStoreFetchRequest(query: query) private var patients + + @CareStoreFetchRequest(query: query()) private var patients @StateObject private var viewModel = ProfileViewModel() @ObservedObject var loginViewModel: LoginViewModel @@ -79,6 +79,11 @@ struct ProfileView: View { viewModel.updatePatient(publishedPatient.result) } } + + static func query() -> OCKPatientQuery { + OCKPatientQuery(for: Date()) + } + } struct ProfileView_Previews: PreviewProvider { diff --git a/OCKWatchSample Extension/Main/Care/CareView.swift b/OCKWatchSample Extension/Main/Care/CareView.swift index 10bf8a0..26de90c 100644 --- a/OCKWatchSample Extension/Main/Care/CareView.swift +++ b/OCKWatchSample Extension/Main/Care/CareView.swift @@ -13,12 +13,8 @@ import SwiftUI import os.log struct CareView: View { - private static var query: OCKEventQuery { - var query = OCKEventQuery(for: Date()) - query.taskIDs = [TaskID.stretch, TaskID.kegels] - return query - } - @CareStoreFetchRequest(query: query) private var events + + @CareStoreFetchRequest(query: query()) private var events var body: some View { ScrollView { @@ -31,6 +27,12 @@ struct CareView: View { } } } + + static func query() -> OCKEventQuery { + var query = OCKEventQuery(for: Date()) + query.taskIDs = [TaskID.stretch, TaskID.kegels] + return query + } } struct ContentView_Previews: PreviewProvider {