Closed GordonNY closed 5 years ago
Good point. And it appears that you can't filter out subclasses at predicate level: https://stackoverflow.com/questions/16636338/nspredicate-that-filters-out-subclass-results
I see three workarounds (for MagicalRecord 2.x):
let controller = A.mr_fetchAllSorted(by: "id", ascending: true, with: nil, groupBy: nil, delegate: nil)
controller.fetchRequest.includesSubentities = false
A.mr_performFetch(controller)
let results = controller.fetchedObjects
let controller = A.mr_fetchAllSorted(by: "id", ascending: true, with: nil, groupBy: nil, delegate: nil)
let results = controller.fetchedObjects?.filter { type(of: $0) == A.self }
let request = A.mr_requestAllSorted(by: "id", ascending: true, with: nil)
let controller = A.mr_fetchController(request, delegate: nil, useFileCache: false, groupedBy: nil, in: NSManagedObjectContext.mr_contextForCurrentThread())
controller.fetchRequest.includesSubentities = false
A.mr_performFetch(controller)
let results = controller.fetchedObjects
For example, A is the parent entity of B. A.mr_fetchAllSorted() returns the objects including both A and B..