Apple Health Frameworks

Nov 29 2022 Swift 5, iOS 15, Xcode 13

Part 2: Dive Into More Details

9. Work With StoreManager

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 8. Create a CheckIn Task Next episode: 10. Make a Follow-Up Vaccination Task

This video Work With StoreManager was last updated on Nov 29 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

Part 2, Episode 10, Work with StoreManager

In this episode, I want to show you how to work with CareKitStore using StoreManager. Until now, you had the StoreManager on the memory, which means every time you opened the app, it was empty, but from now on, I want to tell you how to store it on the disk, so you don’t need it to do the onboarding task again and again.

      type: .onDisk(protection: .none)
static func fetchTasks(on date: Date, storeManager: OCKSynchronizedStoreManager, completion: @escaping([OCKAnyTask]) -> Void) {
    var query = OCKTaskQuery(for: date)
    query.excludesTasksWithNoEvents = true

    storeManager.store.fetchAnyTasks(
      query: query,
      callbackQueue: .main) { result in
      switch result {
      case .failure:
        Logger.task.error("Failed to fetch tasks for date \(date)")
        completion([])
      case let .success(tasks):
        completion(tasks)
      }
    }
  }
TaskViewModel.fetchTasks(on: date, storeManager: self.storeManager) { tasks in
            tasks.forEach {
              guard let id = TaskModel(rawValue: $0.id) else { return }
              if id == TaskModel.checkIn {
                TaskViewModel.makeTaskViewController(
                  input: id,
                  date: date,
                  storeManager: self.storeManager,
                  listViewController: listViewController,
                  delegate: self)
              }
            }
          }