Hi there,
In short, I'm trying to use CoreData in my ShieldConfigurationDataSource extension. Trying to fetch from core data at all seems to cause the shield to render it's default look. I already added the extension to an app group + configured my persistence store to use the app group. Below is my code, any help is appreciated:
// Shield extension
override func configuration(shielding application: Application) -> ShieldConfiguration {
do {
let appSelectionId = "***"
let blockedItemReq = ...
blockedItemReq.predicate = ...
let moc = PersistenceController.shared.container.viewContext // Commenting this and the bottom out makes it work, but I need the data!
let blockedItemRes = try moc.fetch(blockedItemReq)
let shieldTitle = ShieldConfiguration.Label(text: "Hello there", color: .red)
return ShieldConfiguration(backgroundColor: .black, title: shieldTitle)
}
catch {
let shieldTitle = ShieldConfiguration.Label(text: "ERROR \(error.localizedDescription)", color: .white)
return ShieldConfiguration(backgroundColor: .black, title: shieldTitle)
}
}
// Persistence Controller
init(inMemory: Bool = false) {
container = NSPersistentContainer(name: "AppBlockerOne")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
else {
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.appblockerone")!
let storeURL = containerURL.appendingPathComponent("AppBlockerOne.sqlite")
let description = NSPersistentStoreDescription(url: storeURL)
container.persistentStoreDescriptions = [description]
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.automaticallyMergesChangesFromParent = true
}