【发布时间】:2017-06-24 07:08:49
【问题描述】:
我正在保存一些数据 - 姓名和姓氏。但我不知道如何获取一些数据。 这是我的代码,但我不知道为什么它不起作用 - 我不知道
class UserIN: NSManagedObject {
@NSManaged var name: String?
}
我创建 NSManagedObject 子类
func fetching(){
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let usersFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "Users")
do {
let fetchedUsers = try context.fetch(usersFetch) as! [UserIN]
print(fetchedUsers)
} catch {
fatalError("Failed to fetch employees: \(error)")
}
}
请告诉我它不显示提取数据的原因。
【问题讨论】:
-
类名默认与实体名相同。你改了类名吗?如果是这样,您必须在数据模型中设置它以表示实体引用此类。
-
请说明您是如何创建(保存)数据的。