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!
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
It should be as simple as adding CoreData.framework to your target:
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.
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.
I had the same problem. It was solved by the following steps:
Remove Reference to CoreData.framework from Frameworks group in Xcode.
Remove CoreData.framework from 'Link Binary with Libraries' in target settings.
Quit Xcode (Cmd + Q).
Open your project folder in Finder and delete CoreData.framework file.
Start Xcode, open your project. Now you may to add the CoreData.framework in 'Link Binary with Libraries'.
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.
Related
QUESTION: What and where is the pre-compiled header file in an xcode project?
PROBLEM: I need help with xcode.
DISCLAIMER: I know nothing about xcode.
BACKSTORY: I have an app built with appcelerator, which builds an xcode project for me. Now I want to make it Citrix Ready which by this press release should be easy http://www.appcelerator.com/press-releases/citrix/ but < rant > they have no documentation on this, no one at appcelerator seems to care, and they say to use SO for support (which I did and it got me the peer pressure badge, yay!).< /rant >
So, since they suck I'm trying to do it myself directly in xcode and with a question that is acceptable within SO guidelines.
SITUATION: I'm up to step 3 of the steps to do this are listed on the Citrix website: http://docs.citrix.com/en-us/mdx-toolkit/10/xmob-mdx-dev-guide-overview/xmob-mdx-dev-ios-apps.html#par_anchortitle_33e5
Step 3: Revise a line of code in the pre-compiled header file in the app project to import WorxEnable.h from Worx.framework as shown in the following example
#ifdef__OBJC__
_
//import MDX extensions
#import <AVFoundation/AVFoundation.h>
#import <SystemConfiguration/SCNetworkReachability.h>
#import <Worx/WorxEnable.h>
#endif
I just don't know what or where the pre-compiled header file is.
Any help would be much appreciated.
I look forward to posting questions about steps 4 and 5 asking what those mean and how to do them:
Step 4: Add the following to “other linker flags” if they do not already appear:
Step 5: Add the following frameworks and libraries:
Thanks!
Hum, I think it's the .pch file.
If it not exist in your Xcode project (Xcode does not create automatically this file now), create one like myproject-Prefix.pch (just an example).
And in the build settings, add your file path in Prefix Header
My pch file :
#import <Availability.h>
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <SystemConfiguration/SystemConfiguration.h>
#endif
Assuming I got a Framework called Foobar. When I try compiling my iOS project I get the compiler warning:
Umbrella header for module 'Foobar' does not include header
'Foobar-umbrella.h'
I don't get what this 'Foobar-umbrella.h' is and why it isn't included. Some details about my project:
An iOS 8 App project mostly written in Swift. A little bit Objective-C
The 'Foobar' framework is a separate project mostly written in Swift which I have included as a subproject to my main project.
It has been included by embedding it in build phases and depending on it. But I am not explicitly linking against it.
I use Cocoapods, but 'Foobar' is not included as a pod.
The umbrella header is the 'master' header file for a framework. Its use is that you can write
#import <UIKit/UIKit.h>
instead of
#import <UIKit/UIViewController.h>
#import <UIKit/UILabel.h>
#import <UIKit/UIButton.h>
#import <UIKit/UIDatePicker.h>
and so on.
For me, <XCTest/XCTestCase+AsynchronousTesting.h> is included in <XCTest/XCTest.h>. Maybe it is not for you? In that case, add the
#import <XCTest/XCTestCase+AsynchronousTesting.h>
manually.
I have a problem
#import Foundation;
and I see:
#import vs #import - iOS 7
and I set "Enable Modules" to "YES"
and my problem is not solved
I got this warning in a zero-swift project whenever I tried to add the #import SafariServices; statement.
Solution:
Enable the modules. Go to the Target > Build Settings and set the Enable Modules (C and Objective-C modules) to YES.
OR
Note: I haven't verified this potential solution, but probably worthy of consideration if there are side effects caused by this solution.
Rather than enabling modules to entire project, we can enable modules for a specific file which is importing c++ file. Go to build phases -> Compile Sources -> Select the file -> Add compiler flag -fmodules
The possible cause is that you use Objective-C++. Then modules get disabled despite the proper build settings.
I've been mixing ObjC, ObjC++, C++, and Metal. Whenever I get the "use of #import when modules are disabled" I try
replacing:
#import Name;
with:
#import "Name/Name.h"
example, replace:
#import Metal;
#import MetalKit;
#import CoreVideo;
with:
#import "Metal/Metal.h"
#import "MetalKit/MetalKit.h"
#import "CoreVideo/CoreVideo.h"
It seems to work.
Check if you are using #import "ProductName-Swift.h" somewhere in .mm files or any other files other than objc files.
Because if you use this import in cpp files then modules gets disabled automatically.
I have a small prefix header file
#ifndef UP_FOR_IT_PrefixHeader_pch
#define UP_FOR_IT_PrefixHeader_pch
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <Parse/Parse.h>
#import "ABConstants.h"
#import "ABCache.h"
#endif
#endif
it can't find Parse.h. I linked it from Link binary with libraries everything seems right but whatever I tried it does't compile. I tried removing the lib and import again but nothing changed. Removed indexes on derived data but still no clue.
What should I try? It took 2 hours and still not working.
Xcode 6. IOS 8
Goto Build Settings > Apple LLVM 6.0 - Language > Prefix Header
Add here: $(SRCROOT)/PrefixHeader.pch
If $(SRCROOT) not working for you, set the value of 'Prefix Header' to your PCH file name, with the project name - i.e. for project named 'Test-Project' and PCH file named 'Test-Project-Prefix.pch' and add the complete string 'Test-Project/Test-Project-Prefix.pch'
Select your project (named "Project" for example) and click on "ProjectTests" (in TARGETS section).
Then, go to Build Phases > Link Binary With Libraries and add Parse.framework
Just in case rest of the answers doesn't work for someone. Try changing Under "Target Membership", the scope of your targets from public to project. Hopefully it helps.
If you are using cocoapods, you may checkout this link.
I got this problem but none of the solution above worked for me.
I'm using cocoapods, the reason is that in the Podfile I only linked pods to default target. If you are going to add another one, you should add another target configuration in Podfile(target:'target' do). Usually the new one is the same to the original one, you could use link_with to make life easier.
But life is not always that easy. It looks like that link_with is deprecated. You may checkout this link.
.pch
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "thing.h"
#endif
I have a pretty large project I'm trying to debug and I have a suspicion the problem is in thing.h
From what I understand the .pch file is included in EVERY .m and .h in the project.
Is it possible to have it not included in just one or two files? For debugging I would like to not include thing.h in just one test file, but removing it from the .pch causes a cascading nightmare across the project.
This is a really old question but I just ran into this issue. I was able to solve the problem by wrapping the pch file with a ifndef SOME_NAME. Then in the project settings on each specific file I wanted it to not be included I added a compiler flag of -DSOME_NAME=1. Hope that helps someone in the future.