This question already has answers here:
How to apply the type to a NSFetchRequest instance?

(9个答案)


4年前关闭。




我打开了我的一个项目,Xcode要求我将源代码更新为Swift 3。单击保存后,出现了预期的错误。创建fetchRequest时发生错误。 (第8行中的错误消息错误)
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let appDelegate = UIApplication.shared().delegate as! AppDelegate

    let managedContext = appDelegate.managedObjectContext!

    let fetchRequest = NSFetchRequest(entityName:"Sessions") //<- Error error message: generic parameter 'ResultType' could not be inferred

        do {
            sessions = try managedContext.fetch(fetchRequest) as! [Sessions]
        } catch let error as NSError {
            print("Could not fetch \(error), \(error.userInfo)")
        }

        print("fetched")

        self.tableView.reloadData()
    }
}

最佳答案

我自己也有解决方案。我刚从
let fetchRequest = NSFetchRequest(entityName:"Sessions")

let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName:"Sessions")

关于ios - 更新到Swift 3后出现的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38423788/

10-11 03:55