-1
Ich muss jede Zeichenfolge wie ein Objekt speichern, aber in der folgenden Methode speichert nur die letzte Zeichenfolge.Swift 3 mehrere Kerndaten speichern
Können Sie mir bitte sagen, wie kann ich alles speichern?
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
if let doc = HTML(html: sentHTML, encoding: .utf8) {
print(doc.title!)
var kCounter = 2
var Variab = false
let newInfo = NSEntityDescription.insertNewObject(forEntityName: "MarksTable", into: context)
for link in doc.xpath("//td | //link") {
if (kCounter % 2) == 0 {
newInfo.setValue(link.text!, forKey: "lesson")
}
if (kCounter % 2) == 1 {
newInfo.setValue(link.text!, forKey: "mark")
}
kCounter += 1
do
{
try context.save()
print("saved ",link.text!)
}
catch
{
}
}