I am working on a WatchKit Extension with using CoreData.
The CoreData StoreURL is the same like in the iOS App. Within the iOS App it's working like expected.
In the SQLite-File (which is used by both (App + WK-Extension)) there is the new data. So it seems that CoreData in the WatchKit-Extension is fetching the data from a cache.
How can I disable the cache or force loading the new data?
This is how I fetch the Data:
- (NSArray*)fetchAllActive:(NSError**)error
{
NSFetchRequest* fetchRequest = [super fetchRequestForTemplate:@"AllActiveReminder" substitutionVariables:nil];
NSArray* result = [super fetchWithRequest:fetchRequest error:error];
return result;
}
A call of [managedObjectContext refreshObject: mergeChanges:]
does only working in a for-loop for the WKTable.
Thanks!
I came across the same problem when creating an Action extension that shared a Core Data store with it's containing app. The solution that I came across that works for me is to set the stalenessInterval on the Main Queue NSManagedObjectContext as follows inside of your extension:
objectContext.stalenessInterval = 0.0;
This tells the context in the extension to fetch new data every time and ignore the cache.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With