Created
January 18, 2021 09:59
-
-
Save fredriccliver/b06bd1a389ee17d4485989493e12c8ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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