UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

FetchRequest not being found

Forums > SwiftUI

Hi,

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!

Thanks,

Ed

3      

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

4      

Hi,

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

3      

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,

DMG

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.