Crystal
Crystal

Reputation: 29458

Importing Core Data to existing project fails

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:

#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!

Upvotes: 6

Views: 1134

Answers (4)

kevinl
kevinl

Reputation: 4214

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

Upvotes: 2

shelbalart
shelbalart

Reputation: 43

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

  1. Remove Reference to CoreData.framework from Frameworks group in Xcode.
  2. Remove CoreData.framework from 'Link Binary with Libraries' in target settings.
  3. Quit Xcode (Cmd + Q).
  4. Open your project folder in Finder and delete CoreData.framework file.
  5. Start Xcode, open your project. Now you may to add the CoreData.framework in 'Link Binary with Libraries'.
  6. Don't forget to add #import <CoreData/CoreData.h> into <projectName>-Prefix.pch located at Supported Files. My prefix header seems like this:

`

#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.

Hope this helps for anyone who reads it.

Upvotes: 0

Mundi
Mundi

Reputation: 80265

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.

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.

--> Try changing your attribute names.

Upvotes: 0

Dan Fairaizl
Dan Fairaizl

Reputation: 2170

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

enter image description here

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__
    #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.

Upvotes: 1

Related Questions