I have a data model with just one record, a NSFetchResult instance that was set up with fetchOffset at 10.
Assets: NSManagedObject
let fetchRequest = Assets.fetchRequest()
After saving a new data model I run the request I got 2 entities from the fetch result.
let fetchResult = try context.fetch(fetchRequest) as? [Assets]
I scheduled a dispatch queue to run exactly the same fetch request after 10s then the result is empty as I expected.
let fetchResult = try context.fetch(fetchRequest) as? [Assets]
Can you give me any advice?
How can I should do to make the fetch result work as expected?
CodePudding user response:
I suspect you have unsaved changes in your context in the first call. Try setting:
fetchRequest.includesPendingChanges = false