Swift 3 Core Data "Entity" error: `Use of undeclared type`
Solution 1
Dont forget import CoreData
to your subclass
Solution 2
This happened possibly as Xcode is unable to determine the path of the .xcdatamodel
, a related error can be seen when cleaning the the project. This error happen to one of my project when changing the name of the .xcdatamodel
.
Resolution involves the following:
- go to Product -> Clean (Shift-Cmd-K)
- if the error persists
- Ctrl-click (right-click) the problematic
.xcdatamodel
-> Show in Finder - Drag the
.xcdatamodel
to import to the project, a new entry should be created - Remove the previous
.xcdatamodel
entry.
- Ctrl-click (right-click) the problematic
- Build (Cmd-B) to confirm the fix
Solution 3
I was troubled the same error,I used to Xcode 8.2.1 . I cleaned the project ,closed the Xcode and reopen it ,the error was eliminated after building.
Solution 4
Highlight the Data Model, go to Editor -> Create NSManagedObject Subclass...
This solved the error
Solution 5
In my case, Xcode
wasn't finding the automatically generated class, which is something like that:
//
// Teste+CoreDataClass.swift
//
//
// Created by Laura Corssac on 2/2/20.
//
// This file was automatically generated and should not be edited.
//
import Foundation
import CoreData
@objc(Teste)
public class Teste: NSManagedObject { }
After quitting Xcode
and reopening it, my problem was solved.
PlateReverb
I'm working on completing my first commercial app for iOS. It's a synthesizer and compositional tool called A.I. Synth.
Updated on July 02, 2022Comments
-
PlateReverb almost 2 years
Use of undeclared type 'Transcription'
I'm following this simple tutorial of Core Data in Swift 3 (https://learnappdevelopment.com/uncategorized/how-to-use-core-data-in-ios-10-swift-3/)
and I get the above error on the line:
let fetchRequest: NSFetchRequest<Transcription> = Transcription.fetchRequest()
I double checked and the Entity "Transcription" is spelled correctly in my .xcdatamodeld file
The tutorial was designed for Swift 3, but there was another change since it was released that I fixed, so I'm guessing some other change to Swift in the past 2 months has caused this error.
I'm brand new to Core Data, so I don't know how to debug this. I'd be very grateful for a solution!