I'm trying to fetch some values out of a CoreData store, typed as an array of the generated CoreData Entity classes. Is this possible?
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let responseFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Response")
do {
var responses = try managedContext.fetch(responseFetchRequest) as! [Response]
print(responses[0])
} catch {
print("Failed!")
}
This print statement is only printing the following to console:
Is it wrong to use these entity classes as such? I've used them before for creating data (see usage below), so surely you can use them as models too?
let responseEntity = NSEntityDescription.entity(forEntityName: "Response", in: managedContext)!
let response = Response(
context: NSManagedObject(
entity: responseEntity,
insertInto: managedContext
).managedObjectContext!
)
Also, for context, this is what I mean by a CoreData entity:


nilthough?