Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created January 18, 2021 09:59
Show Gist options
  • Save fredriccliver/b06bd1a389ee17d4485989493e12c8ab to your computer and use it in GitHub Desktop.
Save fredriccliver/b06bd1a389ee17d4485989493e12c8ab to your computer and use it in GitHub Desktop.
// ...
import CoreData
// ...
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "AudioCache")
container.loadPersistentStores { description, error in
if let error = error {
fatalError("Unable to load persistent stores: \(error)")
}
}
return container
}()
// MARK: - Core Data Saving support
func saveContext() {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch let error as NSError {
print("Error: \(error), \(error.userInfo)")
}
}
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment