Post

Replies

Boosts

Views

Activity

Prevent CloudKit sync / trigger sync manually
CloudKit sync with Core Data is quite an energy expensive task which can drain the battery quickly. As far as I found out, CloudKit triggers a sync when it thinks it's convenient to do so. I discovered, that in my app the sync is triggered almost every time I save the context, which is quite often. In my case it's only necessary to sync after certain events happened and not every time I save the context. So it's quite an energy waste right now. Since I am not able to reduce the amount of context saves, I try to Implement a logic that enables me to prevent the sync until I release it again. So far I was not able to find any built in methods that would allow me to do that. Any Ideas how I could implement that? Is there a way to temporarily disable CloudKit completely without harm?
1
0
1.2k
Aug ’22
Core Data, CloudKit - Deduplication causes nil relationships
I followed along apples Article for relevant store changes, mainly for data deduplication. https://developer.apple.com/documentation/coredata/consuming_relevant_store_changes I also downloaded the Core Data / CloudKit Demo App which already has a deduplication process. https://developer.apple.com/documentation/coredata/synchronizing_a_local_store_to_the_cloud In the Demo project I observed that more often than not, Posts loose their relationship to Tags. After some investigation I assume that this happens, when a Tag which has a relationship to a Post, gets deleted during the deduplication process, before the relevant Post was synced to the device. When the Post now arrives on the device, its related Tag Object does no longer exist. Therefore it's also not possible to find the retained, deduped Tag-Object which should be connected to the Post. I'm wondering why this was implemented that way in the Demo Project, as this really causes critical data loss. I have also no Idea how to avoid it. In the Article, Apple recommends to use Core Datas tombstone to preserve some values of deleted objects. However, there is no further explaination. It's also not implemented in the Demo project. How do I restore lost relationships and how does the tombstone help with it? Example: Before it synced: After it synced:
1
1
1.9k
Jul ’22
Core Data - Accessing Relationship Objects vs. Fetchrequest
I'm wondering if there is a difference between accessing relationship objects directly vs. fetching them with a fetchrequest. What is more efficient and what is Core Data doing under the hood? Example: Let's pretend I have the entities 'Car' and 'Color' with many to many relationship. When I fetch a Car, it's relationship to its colors is a fault until I access it. What does happen when I access it with car.colors ? Is Core Data fetching these Color objects under the hood or have they been there already all the time since fetching the Car object? Does it make a performance difference when instead fetching the colors by a fetchrequest? -> fetchColors(for: car)
1
0
541
Jul ’22
Core Data, CloudKit - Failed to find matching objectIDs for CKRecordID
I am using CloudKit to sync my app across devices. At first everything seems to work as expected but after a while CloudKit seems to get caught in an endless loop and the debug console throws tons of these messages (several thousands in serial): CoreData: debug: CoreData+CloudKit: -[PFCloudKitSerializer applyUpdatedRecords:deletedRecordIDs:toStore:inManagedObjectContext:onlyUpdatingAttributes:andRelationships:madeChanges:error:]_block_invoke(1018): Failed to find matching objectIDs for <CKRecordID: 0x60000330c000; recordName=1E0972A7-D9DD-44A7-88F9-3AD13B32A330, zoneID=com.apple.coredata.cloudkit.zone:defaultOwner> / <CKRecordID: 0x60000330c020; recordName=EE02B981-E54D-486B-95A1-AC0839671C27, zoneID=com.apple.coredata.cloudkit.zone:defaultOwner> in pending relationship: 0xe92e2f9c5a6d27e2 x-coredata://75AFDFFD-8E35-4B9F-AA61-C477073B435B/NSCKImportPendingRelationship/p8626 I guess the most important part is: Failed to find matching objectIDs for <CKRecordID: 0x60000330c000; ... It's just a standard CloudKit implementation without any fancy custom code. I am not able to find anything about it in documentation. Therefore I have no idea where to start to investigate or if this is expected behaviour. I feel like this is slowing down my CloudKit sync quite a lot when I let the app run, the debug messages never end to appear. Usually I'm expecting No more requests to execute. to appear at some point but even after hours this is not the case. Does someone have similar issues or any idea about that?
4
1
1.7k
Jul ’22