0

I'm getting a compiler error with the following code. Scores is dynamically generated data entity (Codegen - Class Defnition). The exact error is:

Cannot convert value of type 'NSFetchRequest<Scores>' to expected argument type 'NSFetchRequest<NSFetchRequestResult>'

override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(animated)

    let request: NSFetchRequest<Scores> = Scores.fetchRequest()
    do {

        scores = try context.fetch(request)
    } catch {
        print("Error")
    }

    tableView.reloadData()
}

The error occurs on the context.fetch() call. Xcode 8.2.1

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Dwight Sands
  • 111
  • 1
  • 8
  • 2
    Replace fetchrequest creation with below line let request: NSFetchRequest< NSFetchRequestResult > = Scores.fetchRequest() This has more leads on similar problem. https://stackoverflow.com/questions/37810967/how-to-apply-the-type-to-a-nsfetchrequest-instance – pkallu Jul 24 '17 at 00:45
  • Ahh I actually read that and missed it. My syntax is for a custom entity class, which is what I started with but later changed to dynamic Codegen. @pkallu suggestion and casting the result to the entity on the fetch line fixed it. Thanks. – Dwight Sands Jul 24 '17 at 05:18

1 Answers1

2

Replace fetchrequest creation with below line

let request:NSFetchRequest<NSFetchRequestResult> = Scores.fetchRequest()

This has more leads on similar problem. https://stackoverflow.com/a/37811827/6249982

pkallu
  • 86
  • 8