我想知道如何讓我的應用程序使用核心數據來保存用戶數據,以便在標籤上按「顯示」時打印存儲的數據(最好是字符串)。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.
}
}