I do have a problem in my iOs application with Xcode. It has been coded in Objective-C, and now I am working on migrating files in Swift, one after another. The code is shared between team members with a versioning system (git).
I started with the core classes and I proceed like this :
@objc
prefix keyword)#import "MyClass.h"
by @class MyClass;
in header files#import "MyProject-Swift.h"
in implementation files (.m) needing itThis process has worked several times, but for some reasons some #import "MyProject-Swift.h"
do not work, and I get the error : 'MyProject-Swift.h' file not found.
According to the different files causing the problem, sometimes, Ctrl+Click will open the "MyProject-Swift.h" file, sometimes not (no matter of the "not found error").
But the file exists and the translated Swift code is present inside it.
Another thing really weird, I tried to re-create new .h and .m files from those using #import "MyProject-Swift.h"
stuff and having the problem, and after that it works (sometimes not, and I get other errors) !
As it works in some cases, I really don't get why it is causing problems for other cases. Of course I searched among dozens of topics but did not find anyone with the same problem.
Could it be an Xcode settings issue, or because of different Xcode versions between team developers ?
Any idea ?
Thanks
Edited :
I complete the issue description with another point of view.
I do have the project in a working state : uses some of my new Swift files, it builds and runs well (some Objective-C files use Swift files).
I know a certain .m file having the issue :
#import "MyProject-Swift.h"
at the beginning, nothing elseReplacing #import "MyProject-Swift.h"
by #import <MyProject-Swift.h>
won't change anything.
I also have this case sometimes : Ctrl+Click opens "MyProject-Swift.h", but Xcode says 'MyProject-Swift.h' file not found (it won't build as well).
Add a header file to your project, named [MyProjectName]-Bridging-Header.h. This will be the single header file where you import any Objective-C code you want your Swift code to have access to.
In your project build settings, find Swift Compiler – Code Generation, and next to Objective-C Bridging Header add the path to your bridging header file, from the project’s root folder. So it could by MyProject/MyProject-Bridging-Header.h or simply MyProject-Bridging-Header.h if the file lives in the project root folder.
You only need one Bridging Header. Add your #import statements to this file, and your classes will now be available in your Swift code without any extra import statements.
I finally came up with the solution on my own : the project.pbxproj file was kind of corrupted after some git merge I guess. Some files of the project were referenced twice in that file, so I deleted the ones I thought being bad (maybe randomly chosen is closer from the truth).
Now it's working like a charm.
In fact this had no effect on the project until I tried to migrate files to Swift !
It would be a great idea to have a tool or function in XCode to reset this project.pbxproj file to the current things we have.
basing on that asumption https://stackoverflow.com/a/31540611/2150954 I solved this problem in this simple way
Find objective C file, in which compiler claims that it can not find YourProject-Swift file there. Remove it file from project and then add.
After that my project successfully compiled and run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With