【发布时间】:2017-03-26 05:52:51
【问题描述】:
我想知道当我在标签上按“显示”时,如何让我的应用程序使用核心数据来保存用户数据以打印存储的数据(最好是字符串)。
谢谢。
这是我插入函数的代码;将它放在名为“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.
}
}
【问题讨论】:
标签: swift core-data label schema