PrefixHeader.pch file can't find headers - ios

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.

Related

Swift 'Could not build Obj-C module 'BranchInvite'

I've been following the instructions for implementing this SDK: https://github.com/BranchMetrics/Branch-iOS-Invite-SDK... below is what I have in my Podfile:
platform :ios, '8.0'
use_frameworks!
target 'My-App' do
pod 'BranchInvite'
end
And here is the error I'm getting...
I've done a lot of troubleshooting to try and figure out the problem, looked at past issues of this reporsitory of this sort, and for some reason I cannot get "BranchWelcomeViewController" (nor BranchInvite) to be recognized/imported. Any idea what I'm doing wrong here? Do I need to populate my bridging-header?
PS: I'm using Xcode 7, Swift 2, OS X 10.10.5, and the latest version of Cocoapods.
Thanks
#SamYoungNY, after debugging using the project you sent over, the best approach using Swift appears to be the following:
Podfile
pod "Branch"
pod "BranchInvite"
your app's bridging header
#import <Branch/Branch.h>
#import <BranchInvite/BranchInvite.h>
#import <BranchInvite/BranchInviteViewController.h>
#import <BranchInvite/BranchInviteTextContactProvider.h>
#import <BranchInvite/BranchInviteEmailContactProvider.h>
#import <BranchInvite/BranchWelcomeView.h>
#import <BranchInvite/BranchWelcomeViewController.h>
#import <BranchInvite/BranchWelcomeControllerDelegate.h>
#import <BranchInvite/BranchWelcomeDefaultView.h>
Then be sure to use your project's .xcworkspace file if you weren't previously. Please let us know if this doesn't work. I'm happy to continue to debug with the actual project you sent over.
I received a lot of help from #st.derrick on this question, and there was something wonky with my version control but in the end I got it working with something I found in the branch.io documentation, the answer is in this link:
https://support.branch.io/support/discussions/topics/6000008855
I can't comment yet but here's the archived text from that thread SamYoungNY linked to.
If you're running into an issue where you know that you've imported >Branch, but Xcode can't seem to find it, we may know the answer. You're >probably seeing a screenshot like the one below:
(Picture not archived)
This likely means that you are importing Branch as a "folder reference" >and not a "group".
Delete the Branch folder from your project
Make sure Branch is no longer in your project's folder (in the file >system, not Xcode)
Re-import Branch and be sure to select "Create Groups" (see screenshot >below)

"Use of '#import' when modules are disabled" Error - Enable Modules & Link Frameworks = YES

I have a project that uses CocoaPods and uses the 'SCLAlertView-Objective-C' pod. That pod uses the #import UIKit; module style import. I've set "Enable Modules (C & Objective-C)" and the "Link Frameworks Automatically" to YES in both my target and project settings. I am still getting the "Use of '#import' when modules are disabled" error.
Is there anything that could prevent Xcode from being able to enable Modules such as the use of a .pch file, any linker flags, or anything else I haven't mentioned? I also tried to clean the project and the project build folder. That didn't have any effect.
Also worth noting is that my project has multiple targets and also has a deployment target of iOS 7.0. My Base SDK is set to iOS 8.3.
I guess your project contains XXX.mm files, however, the xcode only enable C and objective-c modules.
Please have a look at this answer for your reference:
Using #import in objective C in conjunction with __cplusplus
my solution is modify the #import xxx into #import .
Good luck.
I just solved this in a primarily ObjC++ project I was working on that needed to use Firebase.
Simply make a ObjC (.m) file which contains the following.
#import <Foundation/Foundation.h>
#import Firebase; // << swap this for your specific import
That's it, then simply use #include in your .mm files for the specific headers you need. For me that meant:
#include <"Firebase/Firebase.h">
#include <"FirebaseAuth/FirebaseAuth.h">
Just to stress the point, no amount of fiddling with link options made any difference to this "Enable Modules (C & Objective-C)" was already YES. Upgrading to XCode7 didn't seem to help.
Hope this helps someone :)
The build option does not really work as it should. I've solved this problem by adding -fcxx-modules (Objective C++) or -fmodules (Objective C) manually to "C Flags"/"C++ Flags".
Worked for me.

xcode cannot compile NSString

xcode will not compile a FRESH project with only libxml2 and its requirements installed. it returns this error every time.
http://puu.sh/bYc7D/b37d7c6e99.png
I do not know how to resolve this, has anyone had this before?
Most of the standard project templates include a prefix header called project_name-Prefix.pch (and a reference to it in build settings, search for 'prefix').
Since most classes use the Foundation library, including Foundation.h in that header is a good idea. Also make sure that Foundation.framework is included under "Build Phases" -> "Link Binary With Libraries".
If your project isn't setup that way, it might be useful to create a new project using the most basic template (like Single View), observe how its setup and do the same things to your project.
Looks like Foundation isn't imported. Do you have anything in your prefix header file?
Regardless, try importing it into your header:
#import <Foundation/Foundation.h>
Or alternatively if you use modules:
#import Foundation;
Import Fondation? I don't see it at the top of the file.

Compiler Warnings with Mailgun/AFNetworking

I have some compiler warnings in my app which I do not understand:
I have installed Mailgun and AFNetworking using cocoapods. My main project has SystemConfiguration and MobileCoreServices frameworks imported however I still get these issues.
These warnings are unnecessary and my app works perfectly regardless!
How would I go about removing these?
AFNetworking required to link SystemConfiguration.framework and MobileCoreService.framework and import them in you *.pch file.
To do that, go into your target's settings -> Build Phases tab -> Link Binary With Libraries
Click on "+" button and choose those two frameworks (SystemConfiguration and MobileCoreService).
After, open your [Project name]-Prefix.pch file (by default its in Supporting Files group folder) and add
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
IMNPORTANT NOTE
In case if you installed from pods, then you must import those also in 2 places:
1. Pods->AFNetworking->Supporting Files->Pods-AFNetworking-prefix.pch
2. Pods->maligun->Supporting Files->Pods-mailgun-prefix
AFNetworking library wantedly kept #Warning flag for showing the warning. That you need not worry about. Still you want to suppress warning go to your project build phase > Compile sources > click on File that's showing warning > add -w to it. Now build your application. But in general we don't need to worry about warning that are there in library.
Please note suppressing warnings is not a good practice,
Just linking frameworks, will not help, you need to import them in <project>.pch file
(Please note: not all in all Pod dependencies!, only in your project's pch file)
Here is a small guide to resolve this issue!
1) Open your <project>.pch file (that's the precompiled header file)
2) Make sure you have imported the frameworks
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>

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

Resources