I can not save the data in Core Data - please tell me what is wrong - I created a variable in the class - but as I understand it, it does not assign the properties of the objects to be saved.
import UIKit import CoreData let appDelegate = UIApplication.shared.delegate as? AppDelegate class AddVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
var words : Word? override func viewDidLoad() { super.viewDidLoad() ParametrsTV.delegate = self ParametrsTV.dataSource =self } let questions = ["What does mean this word?","Which transcription?","What to connect this pronunciation?","How to write pronunciation for native language?","What part of speech?","Which synonyms can be chosen?","How is used in conversation?","How is used in text?","How is used in musition and film?","How could you apply it?"] @IBOutlet weak var NameWord: UITextField! @IBOutlet weak var ParametrsTV: UITableView! @IBOutlet weak var SaveWord: UIButton! @IBAction func InputNameTW(_ sender: Any) { } @IBAction func SaveButn(_ sender: Any) { if NameWord.text != ""{ save { (complete) in if complete { dismiss(animated: true, completion: nil) } } } } func save(completion: (_ finished: Bool) -> ()) { guard let managedContext = appDelegate?.persistentContainer.viewContext else { return } let word = Word(context: managedContext) word.name = NameWord.text word.translation = words?.translation word.associationByPronunciation = words?.associationByPronunciation word.formOfSpeech = words?.formOfSpeech do { try managedContext.save() print("Successfully saved data.\(word.name, word.formOfMusitionAndCinema,word.pronunciation,word.translation,word.associationByPronunciation)") completion(true) } catch { debugPrint("Could not save: \(error.localizedDescription)") completion(false) } } func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return questions.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "CellAdd") as! CellAddWord cell.labelAtribute.text = questions[indexPath.row] switch indexPath.row { case 0: if cell.labelAtribute.text == "What does mean this word?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = words?.translation} case 1: if cell.TextAttributes.text != "Which transcription?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.pronunciation} case 2: if cell.TextAttributes.text != "What to connect this pronunciation?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.associationByPronunciation} case 3: if cell.TextAttributes.text != "How to write pronunciation for native language?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.nativePronunciation} case 4: if cell.TextAttributes.text != "What part of speech?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.partOfSpeech} case 5: if cell.TextAttributes.text != "Which synonyms can be chosen?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.synonymsForLeanLang} case 6: if cell.TextAttributes.text != "How is used in conversation?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.formOfSpeech} case 7: if cell.TextAttributes.text != "How is used in text?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.formOfText} case 8: if cell.TextAttributes.text != "How is used in musition and film?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.formOfMusitionAndCinema} case 9 : if cell.TextAttributes.text != "How could you apply it?" && cell.TextAttributes.text != ""{ cell.TextAttributes.text = self.words?.whereMeeting} default: print("Don't save") } return cell } }