我想知道如何让我的应用程序使用核心数据来保存用户数据,以便在标签上按“显示”时打印存储的数据(最好是字符串)。Swift显示核心数据在标签上
谢谢。
这里是我的代码插入功能;将它放在名为'display'的标签上会是什么样子?
@IBAction func insertStudent(_ sender: AnyObject) {
let context = getContext()
let entityDescription = NSEntityDescription.entity(forEntityName: "Contacts", in: context)
let contact = NSManagedObject(entity: entityDescription!, insertInto: context) as! Contacts
contact.name = name.text
contact.address1 = address1.text
contact.address2 = address2.text
contact.city = city.text
contact.grade = grade.text
contact.state = state.text
contact.zip = zip.text
var error: NSError?
//save the object
do {
try context.save()
status.text = ("saved!")
} catch let error as NSError {
status.text = ("Could not save \(error), \(error.userInfo)")
} catch {
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}