我是Swift的初学者,我正在尝试完成我的第一个应用程序。在编写代码时,我看到它说:
使用未声明的类型“ NSFetchRequest”。
我的代码行:
override func viewWillAppear(_ animated: bool) {
super.viewWillAppear(animated)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let fetchRequest = Birthday.fetchRequest() as NSFetchRequest = Birthday
do{
birthdays = try context.fetch(fetchRequest)
}
答案 0 :(得分:1)
添加
import CoreData
并将获取请求行更改为
let fetchRequest : NSFetchRequest<Birthday> = Birthday.fetchRequest()