I am trying to save JSON data received from a web service into my core data model. This works by swiping left from a table view cell to save. When I try to look at the saved data from a database, nothing shows. Can someone please have a look? The code below handles persistence.
https://github.com/lexypaul13/Covid-News
https://github.com/lexypaul13/Covid-News
Error Message: [] nwprotocolgetquicimageblockinvoke dlopen libquic failed
Code Block func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { let save = UIContextualAction(style: .normal, title: "Save") { (action, view, completionHandler) in completionHandler(true) CoreDataManger.sharedInstance.createData() } save.backgroundColor = .systemBlue let swipe = UISwipeActionsConfiguration(actions: [save]) return swipe } _
Code Block class CoreDataManger: NSObject { static let sharedInstance = CoreDataManger() private override init() {} var newsCoreData: [News] = [] var article = ArticlesData() // MARK: - Core Data Saving support func createData(){ //As we know that container is set up in the AppDelegates so we need to refer that container. DispatchQueue.main.async(execute: { [self] in guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } //We need to create a context from this container let managedContext = appDelegate.persistentContainer.viewContext //Now let’s create an entity and new user records. let newsEntity = NSEntityDescription.entity(forEntityName: "News", in: managedContext)! for article in self.newsCoreData{ let news = NSManagedObject(entity: newsEntity, insertInto: managedContext) news.setValue("\(article.author ?? "")", forKeyPath: "author") news.setValue("\(article.myDescription ?? "")", forKeyPath: "myDescription") news.setValue("\(article.publishedAt ?? "")", forKeyPath: "publishAt") news.setValue("\(article.title ?? "")", forKeyPath: "title") news.setValue("\(article.urlImage ?? "")", forKeyPath: "urlImage") news.setValue("\(article.urlWebsite ?? "")", forKeyPath: "urlWebsite") } //Now we have set all the values. The next step is to save them inside the Core Data do { try managedContext.save() } catch let error as NSError { print("Could not save. \(error), \(error.userInfo)") } print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)) } )} }