CareKit
CareKit copied to clipboard
Fetch last updated outcome value in SynchronizerView
Currently am updating the outcome value using below snippet and while fetching I see the result values are in different order and I could not fetch the last updated or latest value from result.
controller.appendOutcomeValue(value: outcomeValue, at: IndexPath(item: 0, section: 0), completion: nil)
The below snippet is used in SynchronizerVIew for fetching the values and showing it in UI
let events = context.viewModel.events(forTask: task) events.first?.outcome?.values ---> it gives all the values fetched from user
Could you please provide a solution for fetching the latest value after using append outcomeValue
The sortedOutcomeValuesByRecency method currently isn't public, but copy/pasting the extension within your app and using it directly should address your issue: https://github.com/carekit-apple/CareKit/blob/248c42c4e4ea97ff5fe349361fa6e0a849eab204/CareKit/CareKit/Shared/Extensions/OCKAnyEvent%2BExtension.swift#L34-L52
You should then be able to use it like it's used here: https://github.com/carekit-apple/CareKit/blob/248c42c4e4ea97ff5fe349361fa6e0a849eab204/CareKit/CareKit/iOS/Task/Controllers/OCKButtonLogTaskController.swift#L38
I believe values lose order because they are stored in the OCKStore is a Set instead of an Array, so the order can never be guaranteed, https://github.com/carekit-apple/CareKit/blob/248c42c4e4ea97ff5fe349361fa6e0a849eab204/CareKitStore/CareKitStore/CoreData/OCKCDOutcome.swift#L38
Thanks @cbaker6 for your workaround and suggestions. It worked👍
I believe
valueslose order because they are stored in the OCKStore is aSetinstead of anArray, so the order can never be guaranteed,https://github.com/carekit-apple/CareKit/blob/248c42c4e4ea97ff5fe349361fa6e0a849eab204/CareKitStore/CareKitStore/CoreData/OCKCDOutcome.swift#L38
Absolutely right and the order fetched is random