Created
February 16, 2020 10:48
-
-
Save agiokas/b9dd2e64f91e2a101ce748005b845029 to your computer and use it in GitHub Desktop.
This file contains 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
import CoreData | |
import Foundation | |
import os.log | |
import RxCocoa | |
import RxSwift | |
class CDObservable<T>: NSObject, ObservableType, NSFetchedResultsControllerDelegate where T: NSManagedObject { | |
private var fetchedResultsController: NSFetchedResultsController<NSManagedObject>? | |
private let context: NSManagedObjectContext | |
private let fetchRequest: NSFetchRequest<T> | |
private let results = BehaviorSubject<[T]>(value: []) | |
private var subscriptions = 0 | |
private let serialQueue = DispatchQueue(label: "com.RxFetcher") | |
typealias Element = [T] | |
init(fetchRequest: NSFetchRequest<T>, context: NSManagedObjectContext) { | |
if fetchRequest.sortDescriptors == nil { | |
fetchRequest.sortDescriptors = [] | |
} | |
self.fetchRequest = fetchRequest | |
self.context = context | |
super.init() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment