Open AndrewHartAR opened 9 years ago
This also does not call the delegate:
override func viewDidLoad() {
super.viewDidLoad()
MagicalRecord.saveWithBlockAndWait {
(context: NSManagedObjectContext!) -> Void in
let fetchRequest = Conversation.MR_requestAllSortedBy("mostRecentMessage.eventDate", ascending: false)
self.fetchedResultsController = NSManagedObject.MR_fetchController(
fetchRequest,
delegate: self,
useFileCache: false,
groupedBy: "mostRecentEvent.eventDate",
inContext: context)
self.fetchedResultsController.delegate = self
NSFetchedResultsController.deleteCacheWithName(MessagesViewController.fetchedResultsCacheName())
self.fetchedResultsController.MR_performFetch()
}
}
@ProjectDent i suppose you are doing totally wrong you are not passing the correct context in the the fetch controller also you are not utilizing the Magical Records methods properly
let fetchController = Conversation.MR_fetchAllSortedBy(sort_key, ascending: true, withPredicate: your_predicate, groupBy: groupby_key, delegate: self ,inContext:NSManagedObjectContext.MR_defaultContext())
@ProjectDent You use temporary context provided by MagicalRecord.saveWithBlockAndWait
. This is totally wrong. Also, you should never use saveWithBlockAndWait
functions on main context as you block the UI thread for no good reason.
This code compiles, and should work:
I have my delegate functions declared with
@objc
. But they just don't get called.If I let this live outside the
saveWithBlock
function, usingNSManagedObjectContext.MR_context()
orNSManagedObjectContext.MR_mainThreadContext()
, it crashes with this error:If i use
MagicalRecordStack.defaultStack()!.context
as the context, as I discover it does internally in other functions when you don't specify a context, it doesn't crash. But this seems very dangerous, as it relies on this always being called on the main thread.How am I supposed to implement NSFetchedResultsController?