[英]xcode 8.2 swift 3 Core data — use unresolved identifier
I have created a core data project in xcode 8.2, After that I created an entity say "TestEntity" in .xcdatamodeld我在 xcode 8.2 中创建了一个核心数据项目,之后我在 .xcdatamodeld 中创建了一个实体说“TestEntity”
I am creating entity object by using following code as per given in some tutorials for swift3.我正在根据 swift3 的一些教程中给出的使用以下代码创建实体对象。 enter link description here
在此处输入链接描述
let appDele = (UIApplication.shared.delegate) as! AppDelegate
let cont = appDele.persistentContainer.viewContext
let ent = TestEntity(context:cont)
But I got an error "use of unresolved identifier 'TestEntity'."但是我收到一个错误“使用未解析的标识符‘TestEntity’”。
Product->Buld for testing 为我解决了这个问题(由于一些奇怪的原因,它解决了大多数未解决的标识符错误)
I solved it by changing import Foundation
to import UIKit
.我通过将
import Foundation
更改为import UIKit
来解决它。
Because UIApplication
isn't included in Foundation
framework.因为
UIApplication
不包含在Foundation
框架中。
Try the following things:尝试以下几点:
I can't tell you what solved the issue.我不能告诉你是什么解决了这个问题。 But I glad it works now!
但我很高兴它现在有效!
关闭 Xcode 并重新打开它对我有用。
In my case it was because I had renamed the entity in the .xcdatamodeld file.就我而言,这是因为我在 .xcdatamodeld 文件中重命名了实体。
But renaming the entity in the side menu only applied to the Name property, and not also the Class Name.但是在侧边菜单中重命名实体仅适用于 Name 属性,不适用于 Class Name。 After also renaming the Class Name in the Data Model inspector, it worked.
在数据模型检查器中重命名类名称后,它起作用了。
Just ran into this same problem, was using Xcode-generated Managed Object subclasses.刚刚遇到了同样的问题,正在使用 Xcode 生成的托管对象子类。 Removed references from Xcode project and re-added them.
从 Xcode 项目中删除引用并重新添加它们。 Problem went away.
问题消失了。
将import Foundation
更改为import UIKit
并检查,如果出现同样的问题,关闭 Xcode 并重新打开它会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.