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.
Related
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;
I have an objective-c class that uses swift classes. It all works fine.
I wanted to import the objective-c class into a swift class, so I added its header file to the bridging header. All the sudden I got an error the Projectname_swift.h file is not found.
Any ideas how to resolve this issue?
Is it actually possible?
a circular reference has been created, making it so the Swift code is unable to compile (which leads to the canary error stating that the _Swift.h file is not found).
i have provided a more in depth answer to a similar questions here and here.
long story short, the documentation explicitly says not to this:
To avoid cyclical references, don’t import Swift code into an Objective-C header (.h) file. Instead, you can forward declare a Swift class or protocol to reference it in an Objective-C interface.
Forward declarations of Swift classes and protocols can only be used as types for method and property declarations.
in order to make your code compile again you will need to remove the #import "Projectname_Swift.h" line from the offending Objective-C header. ideally you can simply move the import statement into your .m file, however if you need to publicly expose the Swift class in your ObjC header, then you must forward declare it using #class SomeSwiftClass;.
Let the Xcode build the bridge file from Objective-C to Swift.
Create a temporary directory elsewhere. In there, you create a dummy Xcode Swift project, give the project name the same as your existing Current Project Name.
Then add new file, Objective-C (.m file). The XCode will prompt you to create a bridge header file, click on the create bridge file (the right most button).
Now you locate the header file location in Finder. Then drag into your Current Project of Interest, don't forget to checked the copy file if necessary option. Add necessary #import '.....' in the header file.
You should be good. If everything works fine, delete the dummy project.
Clean derived data. and then #import "ProjectName-Swift.h" in your objective c files.
Go to
Build Settings->Objective-C Generated Interface Header Name
and set the value to YourModule-Swift.h (this is usually already set, this is the filename you need to import on .m file #import "YourModule-Swift.h"
Go to Build Settings and search for "Defines Module", set both values to YES
Create a class in swift with prefix of #objc for example
#objc class mySwiftClass{...}
Build the project again
it will be better if you use error syntax or screen shot. you can simply try this
1. Goto your project on top of right navigation
2. select build settings from middle pain.
3. search for Objective-C bridging header
4. just below this you will find "Generated interface HeaderName"
5. add correct address of your swift file
6. clean and build the project.
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
I know in order to avoid these type of compiling errors a way to solve this is to use #class MyClass in the header instead of import. Then #import the header in the implementation but this is not working for me.
The compile errors does not appear in the header file where I am importing the class but in the imported class' header.
The error I get is
class PVRShell --> Redefinition of 'PVRShell' as different kind of symbol.
Just in case I am using PowerVR and GLView(OpenGl) in my project.
Any ideas of how can I solve this compile error?
Rename your file extension from .m to .mm.
You have to do that if your class use Objective-C++.
I use XCode 4.0 for developing an iOS project.
In my current project, I added the ZXingWidget library correctly but I had to change the .m extension in .mm in the class which implements MyViewController in order to import "QRCodeReader.h" and "ZXingWidgetController.h", the two headers I need to use the ZXing library.
Now, if in the same MyViewController.mm I want to also import my AppDelegate (which is obviously an Objective-C class), I receive a compile error which Xcode signals into other header files that are recursively added by my AppDelegate. These errors are of these kinds:
GCC 4.2 Error - Instance variable '<unnamed'> has unknown size
Expected ';' before 'public'
Expected unqualified-id before 'public'
I believe this is because I don't manage correctly the Objective-C and C++ mixing, and as I comment the line #import "MyAppDelegate.h" the error disappears.
Is there something I can do to fix this problem? Also a workaround could do!
Thanks!
Edit 1: The error does occur only if I import the App Delegate header in that .mm file. In every other .m file of my project I can successfully import the same App Delegate without errors. I feel there's something wrong with the .mm extension and GCC.
SOLVED: I had another external library interface which used this code
#interface Name : NSObject {
#private
#public
id var1;
int var2; // ecc...
}
And the error was pointing to the keyword #public. I commented the #private keyword and everything went just fine! I would be happy if someone could explain me the reason of this.