ich einen Wert aus einem Textview speichern wie auf Coredata soSwift 3 Optional zu String angehängt wird
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let newAttr = NSEntityDescription.insertNewObject(forEntityName: "TableName", into: context)
let attribute_name = textView.text
newAttr.setValue(attribute_name, forKey "attr_name")
context.save()
Dann versuche ich es wie so zurück zu lesen:
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let fetchRequest: NSFetchRequest = TableName.fetchRequest()
let cdRowsArr = try context.fetch(fetchRequest)
let cdRow = cdRows[0]
let txtViewDesc = String(describing: cdRow.value(forKey: "attr_name"))
let attrs = [NSFontAttributeName : UIFont.boldSystemFont(ofSize:15)]
let boldString = NSMutableAttributedStrign(string: txtViewDesc, attributes: attrs)
textView.attributedText = boldString
Und aus irgendeinem Grund, jedes Mal ist die Ausgabe Optional ("originalTextValue") oder Null, wenn es leer ist
Ich verstehe nicht, warum der Wert, den ich will, von optional
umgeben ist 0
Diese letzte Zeile funktioniert –