8

Does anybody have experience using the CloudKit option to DeleteSelf for a CKReference? Here is what I got from the docs:

DeleteSelf

The delete action for referenced records. Deleting a record also deletes any records containing CKReference objects that point to that record. The deletion of the additional records may trigger a cascade deletion of more records. The deletions are asynchronous in the default zone and immediate in a custom zone.

So I've been testing this out, I have created multiple CKReference objects both using the CloudKit Dashboard and by using my app. Whenever I do it with my app I create the reference like so:

let reference:CKReference = CKReference(recordID: savedFriend.friendID, action: CKReferenceAction.DeleteSelf)

I know that it is being assigned to delete itself, because in the dashboard it shows the option checked off: delete self checked off

I must be doing something wrong because whenever I go and manually delete that record that is referenced using the dashboard, or set my app to delete it programmatically, the record disappears but the reference never gets removed. I thought maybe I should just wait and it would happen eventually, but hours later it's still there checked off like it should have deleted itself. It's kind of frustrating because I designed some of my code assuming this would work, now I can have an app that's wasting resources trying to find a CKRecord that doesn't exist anymore. Should I just not rely on this to ever work? I appreciate any help or advice I can get.

UPDATE ~ 04/07/2016

I jumped the gun coming back here and posting an update that the issue had resolved itself. I wasn't totally convinced that the issue wouldn't pop back up so I sought some reassurance last night. I created 5 different CKRecords and created various different CKReference objects to reference them throughout my database. I then proceeded to set the CKReferenceAction.DeleteSelf option on each reference (I tried two manually through the dashboard and the other three done programmatically). Anyways, I waited a few minutes and then deleted the referenced records...after ten minutes the references were all still present. I waited another 5-10 minutes and they were still there so I went to bed assuming they should definitely be gone by morning, right? Wrong! Twelve hours later the CKReference entries are still there and the referenced records are still gone. I'm definitely scratching my head, it seems as though it's a bug with CloudKit. I should mention that I've also noticed some weird behavior in my dashboard. For the past four or so days, down in the bottom left hand corner it has consistently said it's "Reindexing development data", here is a picture for example: reindexing notification

Could that be causing this issue? Is anybody familiar with this issue and knows a way to solve this? Any suggestions would be appreciated. I have filed a bug report with Apple.

Pierce
  • 3,148
  • 16
  • 38
  • 1
    Have you set any access controls or permissions that might be getting in the way? I just did a quick test in the dashboard. I created an object of one type. I created an object of a second type. In the second object I put a reference to the first object and set "DeleteSelf". Then I deleted the first object. The second object was deleted – Paulw11 Apr 07 '16 at 01:08
  • Wow you must have some kind of magic influence over the CloudKit Gods. I've been stressing over this issue for the better part of the whole day, and right after I read your comment, I went to go do some more tests and check my permissions, and now ALL the references that weren't deleting themselves are gone...I didn't touch anything, i just reloaded my dashboard again. I'm happy that they are working out of nowhere now, but I'm also confused. Why would I have experienced approximately an 8 hour delay in removal? That could cause issues if it happens frequently after development. – Pierce Apr 07 '16 at 01:21
  • There can be delays, but usually just a few seconds. I am not sure why you saw 8 hours. – Paulw11 Apr 07 '16 at 01:23
  • Well, I'm just going to hope that it was a fluke, because now I just did another test and it seems to work fine. Thanks for your response, and your magic mojo! ;-) – Pierce Apr 07 '16 at 01:28
  • 1
    @Paulw11 - Do you have an estimate of the average amount of time you noticed between deleting your records, and having the references removed? I'm no longer experiencing delays in the hour range, but I'm still noticing as I continue to test that frequently the references are taking around 10 minutes or so to remove themselves. Is that typical behavior for CloudKit? That still seems excessive and inefficient to me. – Pierce Apr 07 '16 at 02:08
  • The icloud servers must be a very large forest of servers and you got a forest of servers between you and them on the internet too. You need to factor in a delay come what may as they say. Incidently I seen delays too, it is absolutely normal. Do some DB techniques research. – user3069232 Apr 07 '16 at 04:33
  • That makes total sense, you know I definitely expected there to be some delay, but hours is quite excessive! I regret to say that the issue has reappeared. I wanted some reassurance that the issue was resolved so I tested adding some references and deleting the referenced records last night. They weren't gone after about 15 minutes so I went to bed and then checked this morning and they are still there! Well over 12 hours later. It's frustrating to say the least. – Pierce Apr 07 '16 at 17:06
  • 1
    I'm seeing this same issue here in September of 2017 in the newly redesigned CloudKit dashboard. Reference deletion seems unreliable so I'm going to manually delete all references just in case. – Clifton Labrum Sep 06 '17 at 21:39
  • March 2018 and I'm seeing this issue. It's clearly an iCloud bug--here's why: I delete the parent record in CloudKit dashboard, then go to the child record (which should be gone now due to "deleteSelf" setting), and I see the reference to the parent. When I click the arrow that should take me to the parent, the dashboard crashes and asks me to share my crash data with Apple. – James Toomey Mar 17 '18 at 00:56

1 Answers1

0

This is most likely a permission issue.

The cascading delete will only work if the user deleting the records has 'write' permissions to all the records needing to be deleted. So in the CloudKit Dashboard, the cascading delete will only work for the records created with the developer's iCloud account.

See my answer there: https://stackoverflow.com/a/38606004/6643055

Community
  • 1
  • 1
Yann Bodson
  • 1,634
  • 1
  • 17
  • 29