I'm building a share extension for my app, which has meant initialising the Core Data database from the shared directory:
let directory = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: applicationGroupIdentifier)!
let storeURL = directory.appendingPathComponent("database")
MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStore(at: storeURL)
Running the regular app, this all works as expected. But then running the Share Extension, it hits an exception at the first fetch request:
return DataUser.mr_findAll(with: predicate, in: context) as! [DataUser]
Error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'
I'm not sure what could be causing this - as I mentioned, it's running the same code as the regular app at the point it hits the exception.