GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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 try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket 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.