Bridging header doesn't work with two frameworks (Flurry) - objective-c

I have a bridging header in my project (named "Antoine Bellanger-Bridging-Header.h" if this helps) and then when I import my first framework
#import "SWRevealViewController.h"
everything works.
But when I import the second one
#import "Flurry.h"
I have two errors :
Flurry.h file not found
Swift Compiler Error : Failed to import bridging header "/Path"
I would like to know if the compiler error could be caused by the first error ?
Thanks in advance for your help.
EDIT : I have tried this with another project and I have the same error. May it come from the Flurry files ?
#BC_Dilum : Flurry.h is a file that I want to import and from the documentation of the site, it should be included like that. See https://developer.yahoo.com/flurry/docs/analytics/gettingstarted/ios/

Okay I found the solution. I just made a mistake and #BC_Dilum was right by adding
#import "Flurry/Flurry.h"
and not just #import Flurry.h

Related

different import statement in objective c

I was trying to debug a problem we were having in our React-Native on SDK
In our existing code, I see they have done
#import "CleverTap.h"
#import "CleverTapReactManager.h"
and docs says to do
#import <CleverTapSDK/CleverTap.h>
#import <CleverTapReact/CleverTapReactManager.h>
What is the difference between both the imports in swift? or they are the same?
#import "" first check the header in project folder then goes to system library, and the #import<> checks for system headers.
Read: https://swift007blog.wordpress.com/2017/01/13/include-vs-import/

Xcode failed to emit precompiled header?

thanks in advance for the help you will give me.
I have searched this for half a day over the internet yesterday and two hours now and I haven't found anything (more than those two links that did not help FMDatabase.h not found when using route-me library & Failed to emit precompiled header for bridging header)
So here is my problem : I just had in hands a project that a previous developer has been working on, and when I try to launch it, here I have two errors :
failed to emit precompiled header
'/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch'
for bridging header
'/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'
/Users/me/Downloads/Alavoc-ios-master/Alavoc/externalLib/customClass/customClassViewController.h:13:9:
error: 'FMDB/FMDB.h' file not found
There is also one fatal error wroten like this (even if I only have two errors counted, this one appears in the log above the two other ones previously described)
fatal error: module file
'/Users/me/Library/Developer/Xcode/DerivedData/ModuleCache/30E4RG2TSVLXF/Foundation-3DFYNEBRQSXST.pcm'
is out of date and needs to be rebuilt: signature mismatch note:
imported by
'/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch'
/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:13:9:
note: in file included from
/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:13:
#import "customClassViewController.h"
customClassViewController.h line 13 :
#import <FMDB/FMDB.h>
I guess those errors are linked. Do you have any idea where it could come from ?
Thanks in advance for your help guys, I really appreciate it!
Edit for battlmonster (new errors) :
Here are the two errros (file not found (in Alavoc-Bridging-Header.h FMDB.h not found)) and failed to emit precompiled header :
fatal error: file
'/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'
has been modified since the precompiled header
'/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch'
was built note: please rebuild precompiled header
'/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch'
/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:29:9:
error: 'FMDB/FMDB.h' file not found
import
^ 1 error generated. <unknown>:0: error: failed to emit precompiled header
'/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch'
for bridging header
'/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'
This error is about a malformed bridging header. The bridging header is a special header file which lists all Objective-C header files with classes that must be accessible from Swift code. All the bridging header definitions are precompiled in a way to be ready to use from Swift. In your case the bridging header is "Alavoc/bridge/Alavoc-Bridging-Header.h", and it includes a header for customClassViewController.h (from Alavoc/externalLib/customClass), which indicates that your fellow developer wants that customClassViewController is accessible in Swift code.
Now the confusing thing about the bridging header is that it is not recursively including everything, i.e. it just looks on the first level of definitions, and if you import something in your import that you want in Swift, you have to add it to the bridging header explicitly, or else you'll probably get a warning (or an error sometimes). Say you have #import "A.h" in the bridging header, and you have #import "B.h" inside "A.h", then you likely would have to add "B.h" to the bridging header as well.
Now in your example A = customClassViewController, and B = FMDB, and normally you would need to add FMDB to the bridging header, but the thing is that you most likely don't want exporting FMDB to Swift via your bridging header, because it is not meant for this (it is for your own objc code and not for 3rd party libs).
The solution would be to remove line 13 from your "customClassViewController.h". This would likely fix the bridging header compilation, but probably break the customClassViewController, so you need to include FMDB in "customClassViewController.m" and most likely adapt the "customClassViewController.h" to not have anything related to FMDB (or forward-declare those usages with #class X;).
If you move #import <FMDB/FMDB.h> to your implementation (.m) files and still get error: 'FMDB/FMDB.h' file not found, it is likely about FMDB path not being listed in your header search paths.
To solve the last one just include the right path in your "Header Search Paths" in Xcode build settings. Let's say FMDB is located at /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB (and you have /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB/FMDB.h inside), Then you need to open Xcode project settings - select your target on the left - select "Build Settings" on the top - find "Header Search Paths" setting and add /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD path
If you are using cocoapod and it is a framework, suggesting you NOT to include this in pre-compiled header.
Instead, objc files, use:
#import framework_name;

Can I still use bridging header for cocoa pod frameworks?

I used to download Parse frameworks and bridge to my Swift project using bridging header file with this line:
#import <Parse/Parse.h>
Now I just switched to use cocoa pods and things get messed up when I include use_frameworks! in the Podfile. If I keep using the same bridging file, all of the PFObjects become unresolved identifier when build, with error like "Use of unresolved identifier 'PFUser'". This error goes away when I put
import Parse
at the top of each file. But that is pretty much every file since it is a Parse project, let alone other things to import such as ParseUI etc. Is there a way to import once for all as the bridging header used to do?
I tried to change the import line in the bridging header to:
import "Parse.h"
It gives me another error saying "duplicate interface definition for class 'Parse'":
MyApp/Pods/Parse/Parse/Parse.h:66:1: error: duplicate interface definition for class 'Parse'
#interface Parse : NSObject
^
/Library/Developer/Xcode/DerivedData/MyApp-dbdwtdjelpuomaaawugvjubngrvq/Build/Products/Debug-iphonesimulator/Parse.framework/Headers/Parse.h:66:12: note: previous definition is here
#interface Parse : NSObject
^
I checked other questions here but got no luck.
Any help?
Edit: this weird error is shown in picture here: Xcode identified the class but the app cannot compile.

Xcode 6 not identifying some Parse 1.6.1 functions

I just updated my Parse frameworks, which now include Parse.framework, ParseUI.framework, ParseFacebookUtils.framework, and ParseCrashReporting.framework. After importing these frameworks into my swift project and importing the following statements into my bridging file:
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <ParseCrashReporting/ParseCrashReporting.h>
#import <ParseUI/ParseUI.h>
I am getting errors that PFImageView does not have a member named loadInBackground(), although loadInBackground with a completion block works. Similarly, PFObject does not have a member named 'deleteInBackground()', althought .delete() works.
Is anyone else having a similar issue with the new Parse iOS SDK? Am I missing something here, or does this seem like a bug with Parse/Xcode? I've tried cleaning, building, and deleting the derived data for my project multiple times with no luck. Please let me know if there is not enough information provided. Thanks for the help.
Try deleteEventually() instead.

Failed to import bridging header

I've read a lot of questions and answers that deal with a similar issue, but I have yet to find a solution. If anyone could shed some light, that would be wonderful.
I created a Swift project and now I want to combine it with some Objective-C. My "failed to import bridging header" only occurs when I attempt to #import my Chartboost.h file. So, as long as I don't have anything in my bridging header file, Xcode finds it and gives me no issue. But once I add this:
#import <Chartboost/Chartboost.h>
I get the error along with 38 other errors saying "Swift Compiler Error - Function definition not allowed here".
I've correctly imported my framework. And my framework search path is correct. And it's only when I import the Chartboost framework. UIKit and Foundation work fine.
Here is what I did leading up to the issue....First, I created a new Obj-C file and then clicked "Yes when Xcode gave me a pop-up asking if it could configure a bridging header. This created "FunFacts-Bridging-Header.h"
Then I made sure Objective-C Bridging Header path was correct under Swift Compiler - Code Generation.
I even put in a very specific path /Users/me/Desktop/FunFacts/FunFacts-Bridging-Header.h
and it still says "Failed to import".
I've also set Defines Module to "Yes" (because I heard that may help). And my product module name is FunFacts.
Why is FunFacts-Bridging-Header.h failing to import when I try to add #import ?
I answered this in another post: Chartboost integration issues with XCode 6.1
EXPLANATION:
It seems like some pods and libraries don't bother importing the basic frameworks as they expect your code to already have them. This doesn't work with Swift as the way to import frameworks changed.
All you need to do is to add the frameworks needed in your bridging header file.
ANSWER:
It depends on what errors the compiler throws.
If it complains about NSObject, NSString, etc... you need to add
#import <Foundation/Foundation.h> in the top of your bridging header file.
If it complains about UIView, UIButton, etc... you need to add #import <UIKit/UIKit.h> in the top of your bridging header file.
I figured out 2 solutions!
1) This isn't the prettiest way to do it, but I copy and pasted all my code from my Chartboost.h file into my Bridging-Header.h file instead of importing . This worked. But I knew there was a better way, so I kept hunting...
2) The correct solution, I believe, is what I did next. My project's (not target) Framework Search Paths was empty. So, I went ahead and added the path to the Chartboost SDK like so: /Users/me/Desktop/Apps/SDKs/Chartboost
Now it builds and runs with no problem and I didn't have to copy and paste everything into the bridging header. All that was needed was
#import <Chartboost/Chartboost.h>
If anyone is having a similar issue, just read what I did in my question, and then follow it up with this answer.
Had a nearly identical issue and found a solution that worked for me.
My problem was that the Bridging Header was not in ALL my targets.
It was in my project but not my UnitTest target. So I added it to by my UITest and UnitTest and it started working without issue.
The problem like your's puzzled me.
But I found a solution.
#import <Foundation/Foundation.h>
You should put this code (↑) before your code.
This is just my solution (↓).
#import <Foundation/Foundation.h>
#import <Chartboost/Chartboost.h>
Good luck!
This is how I solved it (and works!):
Create yourProjectName-Bridging-Header.h file at the root of your project
Include in that file the .h of the classes you want to expose and use into your swift project
Go to yourProject->Build Settings->Search Paths, and set to Yes the "Always Search User Paths" key.
Set "User Header Search Paths" to your project root path.
That's it.
Apparently, Xcode miss out on third party folders when they are copied into your project
I am on Xcode 6.3 , swift 1.2.
The answer is really very simple.
Make sure you are adding your bridging header path in SWIFT_OBJC_BRIDGING_HEADER under the target section instead of the project section.
If you use CocoaPods this could save your time.
1) The first what you need to do is to check your Podfile it will be like:
target 'YourProjTests' do
inherit! :search_paths
end
target 'YourProjUITests' do
inherit! :search_paths
end
2) Open baseproj configuration and set for test targets correct Pods-Proj.debug , see attached image:
If you have these lines in you bridging header:
#ifndef Bridging_Header_h
#define Bridging_Header_h
#endif /* Bridging_Header_h */
Just delete them, it will solve the problems of Foundation and UIKit.
One case is that if import <Chartboost+Extention/Chartboost+Extention.h> ,
The right way is to import <Chartboost**_**Extention/Chartboost+Extention.h> ,
Just because Pod build will change the framework name of Chartboost+Extention into Chartboost_Extention