NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

FetchRequest not being found

Forums > SwiftUI


I'm working with core data and i've having a little bit of difficulty. I made sure to check the "Use Core Data" box when creating the project and followed the steps for project 11 part 1. However when I try and use the FetchRequest:

@FetchRequest(entity: Student.entity(), sortDescriptors: []) var students: FetchedResults<Student>

I get the error "Cannot find type 'Student' in scope".

I'd be hugely grateful for any help!




Hi Ed

First thing to try if you havent already is to clean build your project and also shut xcode down completely and restart it then do a clean build.

sometimes xcode doesnt recognise your core data objects straight away and it needs some encouragement



I' ve done both these things but unfortunately had no success. Any other suggestions?


hi Ed,

it sounds as if no definition of the Student class has been generated by XCode.

what is the code generation setting for Student in the Core Data model? check that its Codegen indicator is set to "Class Definition" in the Data Model Inspector. if it's set to "Manual/None" or "Category/Extension," that would explain the error.

hope that helps,



Hacking with Swift is sponsored by Instabug

SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred. Instabug's SDK grabs all the logs they need to fix bugs, crashes and performance issues in minutes instead of days. Get screenshots, device details, network logs, repro steps, and tons of other critical insights needed to resolve issues and prioritize product backlogs straight from your dashboard. It only takes a minute to integrate!

Get started now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.