Apple Health Frameworks

Nov 29 2022 · Swift 5, iOS 15, Xcode 13

Part 3: Take Advantage of CareKit & ResearchKit

13. Create OCKDataSeriesConfiguration

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 12. Extract OCKOutcomeValue from ORKTaskResult Next episode: 14. Show Data in Different Charts

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Part 3, Episode 14, Create OCKDataSeriesConfiguration

In this episode, I want to show you how to create different charts using CareKitUI and CareKitStore.

    let muscleSeries = OCKDataSeriesConfiguration(
      taskID: TaskModel.checkIn.rawValue,
      legendTitle: "Muscle Pain (1-10)",
      gradientStartColor: UIColor(red: 1, green: 0.462745098, blue: 0.368627451, alpha: 1),
      gradientEndColor: UIColor(red: 1, green: 0.462745098, blue: 0.368627451, alpha: 1),
      markerSize: 10,
      eventAggregator: .custom { events in
        events
          .first?
          .answer(kind: IdentifierModel.checkinMuscle.rawValue)
          ?? 0
      }
    )
let  headacheSeries = OCKDataSeriesConfiguration(
      taskID: TaskModel.checkIn.rawValue,
      legendTitle: "Headache (1-10)",
      gradientStartColor: UIColor(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1),
      gradientEndColor: UIColor(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1),
      markerSize: 10,
      eventAggregator: .custom { events in
        events
          .first?
          .answer(kind: IdentifierModel.checkinHeadache.rawValue)
          ?? 0
      }
    )
    let tirednessSeries = OCKDataSeriesConfiguration(
      taskID: TaskModel.checkIn.rawValue,
      legendTitle: "Tiredness (0-10)",
      gradientStartColor: UIColor(red: 0.2745098174, green: 0.4862745106, blue: 0.1411764771, alpha: 1),
      gradientEndColor: UIColor(red: 0.2745098174, green: 0.4862745106, blue: 0.1411764771, alpha: 1),
      markerSize: 10,
      eventAggregator: .custom { events in
        events
          .first?
          .answer(kind: IdentifierModel.checkinTiredness.rawValue)
          ?? 0
      }
    )
    let feverSeries = OCKDataSeriesConfiguration(
      taskID: TaskModel.checkIn.rawValue,
      legendTitle: "Temprature (35°C-42°C)",
      gradientStartColor: UIColor(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1),
      gradientEndColor: UIColor(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1),
      markerSize: 2,
      eventAggregator: .custom { events in
        events
          .first?
          .answer(kind: IdentifierModel.checkinFever.rawValue)
          ?? 0
      }
    )
let rangeSeries = OCKDataSeriesConfiguration(
      taskID: TaskModel.motionCheck.rawValue,
      legendTitle: "Range of Motion (degrees)",
      gradientStartColor: UIColor(red: 0.3647058904, green: 0.06666667014, blue: 0.9686274529, alpha: 1),
      gradientEndColor: UIColor(red: 0.3647058904, green: 0.06666667014, blue: 0.9686274529, alpha: 1),
      markerSize: 3,
      eventAggregator: .custom { events in
        events
          .first?
          .answer(kind: #keyPath(ORKRangeOfMotionResult.range))
          ?? 0
      }
    )