Add Combine-based Core Data resolver - #110
Open
nashysolutions wants to merge 1 commit into
Open
Conversation
nashysolutions
commented
Sep 12, 2025
| .removeDuplicates(by: { lhs, rhs in | ||
| lhs.count == rhs.count && lhs.elementsEqual(rhs, by: { $0 == $1 }) | ||
| }) | ||
| .eraseToAnyPublisher() |
Author
There was a problem hiding this comment.
We erase to AnyPublisher early so we can reassign the variable after applying operators like debounce, because each Combine operator produces a different concrete publisher type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Have you considered combine for handling non sendable core data types?
Key points
NSFetchRequestwith SELF IN %@ so filtering, sorting, and optional prefetching happen in the persistent store.DispatchQueue.mainby default) and supports optional debouncing of ID changes.flatMapinnerFuturecompletes or is discarded as soon as its Core Data work finishes.Notes for maintainers
Thread confinement
context.perform { … }.deliverOn(default.main). If you change the scheduler, ensure UI subscribers still hop to main.“Best-effort” semantics
RemoveDuplicates vs debounce
removeDuplicatesand relying on a smalldebounceinstead.Fetch strategy
NSFetchRequestwithSELF IN %@so sorting/prefetching can be done by the store.INlists (thousands of IDs) — consider chunking (e.g. 500–1000 IDs) and concatenating results.Sorting
sortDescriptorsare pushed into the fetch (better than sorting in memory).sortDescriptors; instead, reorder results against the incoming IDs post-fetch.Prefetching
prefetchparameter and setrequest.relationshipKeyPathsForPrefetching = [...]to avoid a wall of faults.Error handling
Never-failing by design (errors map to[]). If you need visibility for diagnostics, consider logging the caughterror(e.g. os_log) or expose a secondary error publisher.Context type
weakisn’t useful here.receive(on:)to the main queue for UI.Model mismatches
T.entity().nameis nil or not in the model, we currently emit[]. You may prefer throwing or surfacing an assertion in debug.Cancellation
flatMapinnerFutureis short-lived and will not retain work beyondperform { … }.