导入现有项目的核心数据失败。

时间:2023-01-27 10:25:23

I have a workspace and I'm trying to add Core Data to it. I went to the project I want to add Core Data to, selected the Target, hit the + sign under Link Wit Binary Files and added the Core Data framework. That part works fine. I can build and run. When I try the next and using this line:

我有一个工作空间,我正在尝试向它添加核心数据。我去了我想要添加Core Data到的项目,选择目标,点击链接Wit二进制文件下的+号,添加Core Data框架。这部分工作正常。我可以构建和运行。当我尝试下一个,用这句话:

#import <CoreData/CoreData.h>

I get build errors. These build errors look like:

我得到构建错误。这些构建错误看起来如下:

"ARC Semantic Issue"
Pointer to non-const type 'id' with no explicit ownership

These errors are present in

这些错误是存在的

NSEntityDescription.h
NSManagedObjectModel.h
NSMnagedObject.h
NSManagedObjectContext.h
NSPersistentStore.h

Does anyone know why I'm not able to import Core Data to an existing iOS project? Thanks in advance!

有人知道为什么我不能将核心数据导入现有的iOS项目吗?提前谢谢!

4 个解决方案

#1


1  

It should be as simple as adding CoreData.framework to your target:

它应该像向目标添加CoreData.framework一样简单:

导入现有项目的核心数据失败。

Click the plus button (+) under Linked Frameworks and Libraries

单击链接框架和库下的加号按钮(+)

Then in your Prefix file (Tabs-Prefix.pch in this case) in the #ifdef __OBJC__ declaration:

然后在前缀文件中(表前缀)。在#ifdef __OBJC__声明中:

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #impport <CoreData/CoreData.h> //Added core data here
#endif

If this does not work, perhaps you have an older version of Xcode installed and the paths are messed up. It could be trying to import an older framework.

如果这个方法不起作用,那么您可能已经安装了一个旧版本的Xcode,而且路径也被打乱了。它可能试图导入一个旧的框架。

#2


2  

In my framework search paths, I had an erroneous path that correctly built once I removed it:

在我的框架搜索路径中,我有一个错误的路径,一旦我移除它,它就正确地构建了:

$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

#3


0  

I think this could be related to your entity definitions. Is it possible that you have declared entities that use the attribute name id? That would typically be a NSNumber type in the model subclasses, i.e. *id.

我认为这可能与您的实体定义有关。是否可能已经声明了使用属性名称id的实体?这通常是模型子类中的NSNumber类型,即*id。

It seems that in this case, the compiler instead of complaining about the *id in the class files, it indicates the id in the header files, which is confusing.

在这种情况下,编译器并没有抱怨类文件中的*id,而是指出了头文件中的id,这很令人困惑。

--> Try changing your attribute names.

——尝试更改属性名。

#4


0  

I had the same problem. It was solved by the following steps:

我也有同样的问题。通过以下步骤解决:

  1. Remove Reference to CoreData.framework from Frameworks group in Xcode.
  2. 从Xcode中的框架组中删除对CoreData.framework的引用。
  3. Remove CoreData.framework from 'Link Binary with Libraries' in target settings.
  4. 从目标设置中的“链接二进制文件”中删除CoreData.framework。
  5. Quit Xcode (Cmd + Q).
  6. 退出Xcode (Cmd + Q)。
  7. Open your project folder in Finder and delete CoreData.framework file.
  8. 在Finder中打开项目文件夹并删除CoreData.framework文件。
  9. Start Xcode, open your project. Now you may to add the CoreData.framework in 'Link Binary with Libraries'.
  10. 启动Xcode,打开项目。现在您可以在“链接二进制与库”中添加CoreData.framework。
  11. Don't forget to add #import <CoreData/CoreData.h> into <projectName>-Prefix.pch located at Supported Files. My prefix header seems like this:
  12. 不要忘记添加#import 到< projectName >前缀。位于支持文件的pch。我的前缀标题是这样的:

`

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>
#endif

`

I don't know how existance of any file in project directory can affect to compile errors, but it works for me.

我不知道project directory中的任何文件的存在如何影响编译错误,但它对我来说是有效的。

Hope this helps for anyone who reads it.

希望这对读它的人有所帮助。

#1


1  

It should be as simple as adding CoreData.framework to your target:

它应该像向目标添加CoreData.framework一样简单:

导入现有项目的核心数据失败。

Click the plus button (+) under Linked Frameworks and Libraries

单击链接框架和库下的加号按钮(+)

Then in your Prefix file (Tabs-Prefix.pch in this case) in the #ifdef __OBJC__ declaration:

然后在前缀文件中(表前缀)。在#ifdef __OBJC__声明中:

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #impport <CoreData/CoreData.h> //Added core data here
#endif

If this does not work, perhaps you have an older version of Xcode installed and the paths are messed up. It could be trying to import an older framework.

如果这个方法不起作用,那么您可能已经安装了一个旧版本的Xcode,而且路径也被打乱了。它可能试图导入一个旧的框架。

#2


2  

In my framework search paths, I had an erroneous path that correctly built once I removed it:

在我的框架搜索路径中,我有一个错误的路径,一旦我移除它,它就正确地构建了:

$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

#3


0  

I think this could be related to your entity definitions. Is it possible that you have declared entities that use the attribute name id? That would typically be a NSNumber type in the model subclasses, i.e. *id.

我认为这可能与您的实体定义有关。是否可能已经声明了使用属性名称id的实体?这通常是模型子类中的NSNumber类型,即*id。

It seems that in this case, the compiler instead of complaining about the *id in the class files, it indicates the id in the header files, which is confusing.

在这种情况下,编译器并没有抱怨类文件中的*id,而是指出了头文件中的id,这很令人困惑。

--> Try changing your attribute names.

——尝试更改属性名。

#4


0  

I had the same problem. It was solved by the following steps:

我也有同样的问题。通过以下步骤解决:

  1. Remove Reference to CoreData.framework from Frameworks group in Xcode.
  2. 从Xcode中的框架组中删除对CoreData.framework的引用。
  3. Remove CoreData.framework from 'Link Binary with Libraries' in target settings.
  4. 从目标设置中的“链接二进制文件”中删除CoreData.framework。
  5. Quit Xcode (Cmd + Q).
  6. 退出Xcode (Cmd + Q)。
  7. Open your project folder in Finder and delete CoreData.framework file.
  8. 在Finder中打开项目文件夹并删除CoreData.framework文件。
  9. Start Xcode, open your project. Now you may to add the CoreData.framework in 'Link Binary with Libraries'.
  10. 启动Xcode,打开项目。现在您可以在“链接二进制与库”中添加CoreData.framework。
  11. Don't forget to add #import <CoreData/CoreData.h> into <projectName>-Prefix.pch located at Supported Files. My prefix header seems like this:
  12. 不要忘记添加#import 到< projectName >前缀。位于支持文件的pch。我的前缀标题是这样的:

`

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>
#endif

`

I don't know how existance of any file in project directory can affect to compile errors, but it works for me.

我不知道project directory中的任何文件的存在如何影响编译错误,但它对我来说是有效的。

Hope this helps for anyone who reads it.

希望这对读它的人有所帮助。