Retrive object but done want to save coredata iOS swift
Problem:
I'm having preview option for some data but if i save other data came from server the temp data also saved in my coredata. How to avoid that?
Solution:
    let context  =  NSManagedObjectContext(concurr
    context.persistentStoreCoordin
The above code solves my problem.
Below are coredata initilisations in my appdelegate.
// MARK: - Get the context
func getContext () -> NSManagedObjectContext {
var context: NSManagedObjectContext?
if #available(iOS 10.0, *) {
        context = persistentContainer.vie
} else {
context = managedObjectContext
}
return context!
}
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: APP_INFO.containerName)
        let dir = FileManager.default.containerU
        if let url = dir?.appendingPathComponent(AP
            let persistentStoreDescription = NSPersistentStoreDescription(u
// Configure Persistent Store Description
            persistentStoreDescription.typ
            persistentStoreDescription.sho
            persistentStoreDescription.sho
            container.viewContext.mergePol
            container.persistentStoreCoord
if let error = error {
print("Container error : ", "Unable to Add Persistent Store")
                    print("Container localizedDescription : ", "\(error.localizedDescription)
}
})
}
return container
}()
lazy var managedObjectContext: NSManagedObjectContext = {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
        let coordinator = self.persistentContainer.persi
        var managedObjectContext = NSManagedObjectContext(concurr
        managedObjectContext.persisten
return managedObjectContext
}()
Comments
Post a Comment