简体   繁体   English

xcode 8.2 swift 3 Core data — 使用未解析的标识符

[英]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’”。

how to resolve that error.如何解决该错误。 在此处输入图片说明 在此处输入图片说明

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框架中。

"use of unresolved identifier 'TestEntity'."Means that you are trying to use a class/struct that is declared nowhere. “使用未解析的标识符'TestEntity'。”意味着您正在尝试使用未在任何地方声明的类/结构。 Possibly you need to generate the NSManagedObjects for your entities.可能您需要为您的实体生成 NSManagedObjects。

在此处输入图片说明

Try the following things:尝试以下几点:

  1. Clean and Build the project after you've added the Entity to your CoreData file将实体添加到 CoreData 文件后,清理并构建项目
  2. Delete the Entity and create it again - redo the step 1删除实体并重新创建 - 重做步骤 1
  3. Close and reopen xcode - redo step 1 and 2关闭并重新打开 xcode - 重做第 1 步和第 2 步
  4. Update xcode to newest version (worked for me) and redo step 1,2 and 3将 xcode 更新到最新版本(对我有用)并重做步骤 1、2 和 3

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM