I'm currently trying to compile my project just after adding some C code.
I'm using the Paul Kocher's blowfish algorithm implementation available on Bruce Schneier's website.
Since I included blowfish.c & blowfish.h in my workspace, my compiler is running crazy. Like if it did not recognize Objective-c code, pointing errors on NSObject class!
I tried to .mm the calling class but the problem stays.
Each answer found on SO talks about including C++ file, but it's not my pb...
Maybe a compiler directive that i'v missed ?
Most likely, what is happening is that the compilation of blowfish.c is using your previously established precompiled header (.pch) file, and that is including an Objective-C framework. Just disable the precompiled header and you should be OK. You might be able to conditionalize those frameworks, but personally, I find precompiled headers more trouble than they’re worth.
Thanks to microtherion, I found the problem.
My .pch file was declared as :
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
#import "AppDelegate.h"
#import "UINavigationController+Rotation.h"
#import "Categories.h"
The 3 last #import'ed files are objective-C.
I've just changed the #endif place to:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "AppDelegate.h"
#import "UINavigationController+Rotation.h"
#import "Categories.h"
#endif
Related
I've installed the Parse and Facebook iOS SDKs for my project in Xcode. My project is written in Swift so I have the following in my bridging header:
#import <Parse/Parse.h>
#import <ParseUI/ParseUI.h>
#import <ParseCrashReporting/ParseCrashReporting.h>
#import <Intercom/Intercom.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
When I build the app, I get 2 errors:
error: 'FacebookSDK/FacebookSDK.h' file not found
error: failed to import bridging header '/Users/ben/AppFolder/MyApp/Bridging-Header.h'
The bridging header is at the directory as shown, so it seems that is dependent on the first error. FacebookSDK.h is in an #import statement at the top of PFFacebookUtils.h:
#import <Foundation/Foundation.h>
#import <FacebookSDK/FacebookSDK.h>
#import <Parse/PFConstants.h>
#import <Parse/PFNullability.h>
#import <Parse/PFUser.h>
FacebookSDK.h does not exist in either the Parse iOS SDK 1.7.1 or the Facebook SDK (presumably 4.0.1) from Facebook's Getting Started page, though I know that FacebookSDK.h was in previous versions.
I tried the approved answer from this SO question without success. Do I need to add something to my bridging header? Should I change the import statement for FacebookSDK.h to reference a different file? Other ideas on how to fix this?
Instead of
#import <ParseFacebookUtils/PFFacebookUtils.h>
use :
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
Make sure to add that V4
This check is in my AFHTTPClient.m file. The check is actually used very frequently throughout the file and the .h file. In one case, it does this:
#ifdef _SYSTEMCONFIGURATION_H
self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
[self startMonitoringNetworkReachability];
#endif
This is still version 1.X of AFNetworking.
Thanks!
I believe this is a pre-processor statement checking that you have linked your project with the SystemConfiguration framework. If not, I believe that AFNetworking was omitting some feature, or maybe it was giving you a nice warning to make sure you don't forget to include this framework, so that AFNetworking could work as expected.
Update
#ifdef _SYSTEMCONFIGURATION_H
#import <netinet/in.h>
#import <netinet6/in6.h>
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <netdb.h>
#endif
So what's going on is if _SYSTEMCONFIGURATION_H is defined (internally by the SystemConfiguration framework), then AFNetworking knows that you included this framework in your project, and so it is importing a bunch of things to make use of it. Otherwise it isn't. This means that you don't have to include this framework if you don't want to.
To solve this problem, type
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
before importing AFNetworking.
I have an Objective-C category that I've been using for a while for both iOS and OSX projects and I want to use it in a Swift project as-is...until I have the time to translate it to Swift.
Here's the top of my category's .h file:
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
#endif
I've included it in the bridging header, but when I build the project for iOS, I get an error saying that it can't find the file Cocoa/Cocoa.h.
Why is it even looking for it? Doesn't the conditional compile still work even in a Swift project? It's still compiling an Objective-C file.
Thanks.
Add #import "TargetConditionals.h" in your source file.
#import "TargetConditionals.h"
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
#endif
Or add "-DTARGET_OS_IPHONE" to the "Other C Flags" section of the target build options.
I am trying to use AFNetworking with Xcode 4.6.2 in my projects. I have added the AFNetworking to my project. I have also added 'SystemConfiguration' and 'MobileCoreServices' framework to the project. I have included the framework header files in the .pch file like below
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "AFNetworking.h"
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
When I try to run the project, I get Clang error from file AFHTTPClient as follows
Command/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 254
Ok , I solved the problem. The issue was with order of import statements in .pch file
I changed the order to as follows basically added 'AFNetworking.h' after import statements for and frameworks.
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "AFNetworking.h"
Also another tip. You also need to add 'Security' framework for AFNetworking to work smoothly. Thanks
I have defined many constants in GlobalVar.h and other .h files. I import these files in the Prefix.pch file like this :
//
// Prefix header for all source files of the 'XXX' target in the 'XXX' project
//
#import "GlobalVar.h"
[...]
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#endif
But when I compile the project all the #defined identifiers are missing and reported as "Use of undeclared identifier XXX".
I searched in the Build settings and the PCH file is set as "Prefix Header"... I am on Base SDK 4.3 and XCode 4.0.2
Do you have hints to debug this ?
Thanks for your help
I came across this error yet, after cleaning DerivedData and restart Xcode I fix it. Hope to help.
move your import to like so
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "GlobalVar.h"
#endif