StanfordSpezi / SpeziScheduler

Scheduler Module for the Stanford Spezi Ecosystem
https://swiftpackageindex.com/StanfordSpezi/SpeziScheduler/documentation/
MIT License
3 stars 3 forks source link

Use Swift Data to Store `Task`s and `Event`s #20

Open PSchmiedmayer opened 11 months ago

PSchmiedmayer commented 11 months ago

Problem

The current usage of the local storage module to store tasks and events is functional but not ideal. It provides limited functionality when querying for tasks and events and does allow limited access to the types from outside of the scheduler module.

Solution

Using Swift Data should allow more flexible querying of data for the scheduler module. Swift Data should also allow views to provide custom queries for tasks and events and reduce the number of redraws of SwiftUI-based views.

The functionality of initializing elements such as notifications should ideally be moved in the types themselves to allow developers to even create tasks outside of the Scheduler module without requiring them to register them with the Scheduler module.

Additional context

You can learn more about Swift Data here: https://developer.apple.com/xcode/swiftdata/

Feel free to use this issue to discuss ideas on how to best implement this functionality and how to improve the internal workings of the Scheduler module.

Code of Conduct

PSchmiedmayer commented 1 week ago

Spezi Scheduler is currently doing all scheduling, planning, and storage of tasks is happening locally on the device. In addition, we have several issues that we have to address here.

In the long run I would suggest that we address some of these elements by multiple elements:

  1. Make Spezi Scheduler based on Swift Data for a better query performance and flexibility
  2. Use the custom Swift Data Storage Backends in iOS 18 to enable local storage using the default Core Data storage as well as an option to write a Firebase/other cloud provider backend storage.
  3. Utilize the new iOS 18 versioned data storage functionality and other extensions to facilitate versioning similar to CareKit which has implemented it internally
  4. Extend the data model to support the storage of different types of tasks including the elements defined in this task.

So far, Spezi Scheduler has served us well for limited use cases but we definitely need more attention and IMO a general strategy shift for this package and I could see a re-architecting of the structure using Swift Data as a great starting point.