Skip to content

Instantly share code, notes, and snippets.

@dilipiOSDeveloper
Last active September 7, 2018 11:51
Show Gist options
  • Save dilipiOSDeveloper/d95ca771cb8c632ab06b51856818690d to your computer and use it in GitHub Desktop.
Save dilipiOSDeveloper/d95ca771cb8c632ab06b51856818690d to your computer and use it in GitHub Desktop.
import Foundation
import CoreData
class DataManager:NSObject{
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "MyDownloadCoreData")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
// MARK: - Core Data Saving support
func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
}
////////// For saving and retriving
// //save coredata
//
// let context = dataManager.persistentContainer.viewContext
// let entity = NSEntityDescription.entity(forEntityName: "VideoCapture", in: context)
// let newVideo = NSManagedObject(entity: entity!, insertInto: context)
//
// newVideo.setValue("video", forKey: "videoTitle")
// newVideo.setValue("\(resumeURl!)", forKey: "videoUrl")
// newVideo.setValue(resumedata, forKey: "resumedData")
//
// do {
// try context.save()
// print("database saved")
// } catch {
// print("Failed saving")
// }
//
//fetchh data
// let request = NSFetchRequest<NSFetchRequestResult>(entityName: "VideoCapture")
// //request.predicate = NSPredicate(format: "videoUrl = %@", "\(resumeURl!)")
// request.returnsObjectsAsFaults = false
// do {
// let result = try context.fetch(request)
// for data in result as! [NSManagedObject] {
// print(data.value(forKey: "resumedata") as! Data)
// }
//
// } catch {
//
// print("Failed")
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment