The documentation states that it is not possible to add an activity with an identical identifier to one already stored (https://github.com/carekit-apple/CareKit/blob/master/CareKit/CarePlan/OCKCarePlanStore.h#L108).
So far, in a number of tests, it seems to me that adding an activity with an existing identifier results in a callback with YES
for the success
parameter and with an error
populated stating an activity with the identifier already exists. No activity is actually added. This seems counter intuitive, but it's not clear to me what the expected behavior should be.
Note that any app that attempts to add an activity after the first start of the app will encounter this behavior. The sample app also depends on it. (https://github.com/carekit-apple/CareKit/blob/master/Sample/OCKSample/SampleData.swift#L94)
Diving into the implementation, unless I'm totally missing something (always possible!), the behavior does not seem to be intended. For one, the app nil checks the "inout" error parameter that was passed into the method two times, when it seems the intention was to nil check the local errorOut
.
Additionally, even if the first check was corrected, I'm not sure I understand it's purpose. It seems to me you'd want to return the subsequent error if an item
were found, or return the value of the errorOut
variable if something else went wrong.
I'm happy to take a stab at solving this, but want to clear up what the actual intended behavior is. Should the store return an error anytime an activity with the same identifier is added? (As far as I can tell, this would mean apps would have to take care to only add activities at first start, or when first added. This may in fact be reasonable, but I wanted to confirm given the behavior of the sample app).