In Xcode 8, When any break point is hit, and I try to print any object in the Xcode debugger, it always prints "Could not resolve type". I have searched enough on the internet. I have checked if EditScheme->Run->Info->BuildConfiguration is set to 'Debug'. Build setting->Optimisation level is set to 'None'. But no clues on why this happens. Could anyone help me out here? Thanks in advance.
I encountered a similar issue with a pure swift framework that doesn't have any bridging headers but non the less had SWIFT_INSTALL_OBJC_HEADER set to YES
It is described in more detail at https://stackoverflow.com/a/51186560/385307
After changing the setting to NO debugging works again.
I had a similar issue with a Swift project which included an Obj-C framework. I had imported the framework in my Swift project using
import Obj-C-Framework
Additionally, I had also created a Bridging-Header file in the Swift project and included the Obj-C-Framework header using
#include <Obj-C-Framework/Obj-C-Framework.h>
This was causing the Xcode debugger to always show 'could not resolve type' when printing objects in breakpoints. Removing the #include in the Bridging-Header fixed the issue and objects print correctly in breakpoints.
TL;DR If your swift project uses an Obj-C framework make sure that the framework headers are not included in your Swift project's bridging header.
I just had the same problem and it had been solved.My project is a Mixed project with both OC and Swift. I found that some .h file import in my Bridging Header file that caused the problem. Definitely, an enum declared in the .h file cause the problem, like this:
typedef NS_ENUM(NSInteger,BadgeAlignment) {
AlignmentCenter,
AlignmentLeft,
AlignmentRight,
};
If i comment the code, everything goes alright.
And I just add a prefix to each element of the enum and the problem is solved for me.
typedef NS_ENUM(NSInteger,BadgeAlignment) {
BadgeAlignmentCenter,
BadgeAlignmentLeft,
BadgeAlignmentRight,
};
I just thinking if there is a conflict with some enum in Swift when convert the .h to Swift.
I'm still confused...
I want to use one third party library which is written in Swift but I am working in Objective-C environment. How to do that? Until now what I have done is:
Drag and drop the third party library into my project.
It is asking for the bridging header I clicked on yes.
In Build settings defines Modules no to yes in both.
Product Module Name showing like $(PRODUCT_NAME:c99extidentifier). I have tried with my project name also.
Now I am getting plenty of errors like below:
pDatePicker.swift:50:9: Consecutive declarations on a line must be separated by ';'
and
Ambiguous use of 'open'.
I am getting errors around 50 to 60 same as above errors. Where is my mistake? Can anybody help me?
Are you able to see projectName-Swift.h file in your project ?
Demo Example is available on github.
https://github.com/hasyapanchasara/UsingSwiftInObjectiveC
If yes then, Hope you have imported #import "projectName-Swift.h" in Objectice C .m file ?
#import "projectName-Swift.h"
Then only you would be able to access objective c files in swift code.
Refer
https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
Check in build setting
Objective-C Bridging Header
ProjectName-Bridging-Header.h has perfect location.
if there is problem with that path than bridging will not work properly , that why when you compile #import "projectName-Swift.h" is not getting generate.
Download
Download above sample project.
Make sure, that your swift version in settings is the same as this lib uses; if not, try to translate it by yourself, or set Use Legacy Swift Version to YES
I have an iOS project written with Objective-C. I created an Swift class in the project, the bridging header file for accessing objective-c in Swift is generated successfully, and it works fine.
My problem is the other way around. I want to import Swift class in objective-c code.
In xcode, target -> Build Settings--> Swift Compiler section, I see Objective-C Generated Interface Header Name field with value myModule-Swift.h , but when I import this header in my objective-c class:
#import "myModule-Swift.h"
I get compiler error:
myModule-Swift.h file not found
and in project, I cannot find this file either. How can I solve this problem?
My xcode version is 6.4
Updated May 2018 Xcode 9.3
Build Settings->Objective-C Generated Interface Header Nameand 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"
(Example, Project named CData)
Same as Step 1, Go to Build Settings and search for "Defines Module", set both values to YES
Create a class that extends NSObject on .swift file
Build the project again
Import YourModule-Swift.h file on .m file (Please notice it's case sensitive, Mymodule !== MyModule)
In case anybody is wondering why after spending hours on this issue it is still unresolved, you might be in a situation similar to mine, where I was actually developing a framework, rather than an app.
In such case, the format of the import statement for Objective-C Generated Interface Header is as follows:
#import <ModuleName/ModuleName-Swift.h>
OMG.. the actual import statement was not "class-Swift.h" but rather "projectname-Swift.h"
You can find the name of the file if you look under build settings->Swift Compiler Code Generation -> Objective-C Generated Interface Header Name
The file was not generated when I dragged in Swift source into the GUI. Only when I right-clicked->Add file to "project". It then asked to generate the header files.
My addition to Daniel Kroms answer:
Never add -Swift.h Header to header. Even if it seems to work. Add the Import to .m file only!
In case you use in your header swift classes, make a forward declaration with #class swiftclassname before your #interface
Then you will see your real errors in your code.
For me, the problem was that I had bitcode on. When I clicked on the "Update to recommended project settings", it changed a few settings which probably the culprit. I turned "Enabled Bitcode" to "No" in the Build Settings and it is fixed now.
I was stacked this for a quite a while. In my case, my target name is something like "my-app" using dash as a part of target name. I tried to #import "my-app-Swift.h", but Xcode kept giving me errors.
I dug under 'DerivedData' folder and I found "my_app-Swift.h". So if you are using some interesting characters for the target name. You may try replace those with underscore _.
I ran into the same issue yesterday and worked for hours to fix it with no avail. Others may have been in the same boat as I. I did all of the steps described above, but nothing worked.
The cause of mine breaking was because of project name artifacts all over my project (from previously changing its name improperly).
If all of the above steps fail, I would suggest doing like I did and renaming your project so that Xcode can reset somethings... That solved the problem for me.
Doing so worked like a charm!
In my case, I have forgotten to check a swift framework to the target/classes that I was using it, really specifically case but it may help someone in the future.
For me the solution was to create a new target. For an unknown reason, the target that I had didn't have that "Swift Compiler - General" settings and thus no to "Objective-C Generated Interface Header Name" field. Having that field specified in the project was not enough.
This is not an exact answer but more of a workaround, but can save you time in some difficult cases. If you, as suggested by some of the the previous answers, can actually find the swift header buried inside the derived data folder, you are allowed to import it using the full path. This is not specific to the swift header, instead it can be applied to any header. Hope you can find this answer useful.
This answer solves my problem, but what's confusing to me is that when I convert bitcode to YES, then clean Xcode DerivedData, bulid again,also Bulid succeeds
I added a bridge header to my app the other day because I was trying to add Objective-C files to my Swift project. I was having trouble getting the connection to work(and I also did not know how to implement the Objective-C files), so I decided I wanted to start over again. I deleted the Objective-C files and the Bridge-Header file and now I am getting an error saying:
<unknown>:0: error: bridging header '/Users/CalebKleveter/Documents/Development/iOS/personal/swift/Projects/Dicey/Dicey/Dicey-Bridging-Header.h' does not exist
Go to Build Settings of your project, find Objective-C Bridging Header row and remove its contents.
Go to targets file->Build Settings->Swift Compiler - General, delete the contents in the same line as Objective-C Bridging Header
Since removing the bridging header or even just leaving it without any content often causes build errors, the quick workaround I've found is leaving the header with nothing but the following two imports:
#ifndef BridgeHeader_h
#define BridgeHeader_h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
Deleting the lines containing SWIFT_OBJC_BRIDGING_HEADER in MyProjectName.xcodeproj/project.pbxproj did the trick for me.
I could not find the Build Settings in my Xcode project as other answers mentioned (maybe because my project is for MacOS, not iOS?).
I've been trying to XLForms in Swift using a bridge header as they suggest.
I've loaded the XLForms Pod and added the bridge file and referenced it in Swift Compiler. The Bridge file references includes #import <XLForm/XLForm.h>.
However, when I try and compile my project I get
Use of undeclared type 'XLFormViewController'
I assume that means it Swift hasn't got access to the library.
I've tried different versions and attempting the setup again, but I can't seem to get it to find it. If I change #import <XLForm/XLForm.h> to #import <XLForm.h> Xcode warns me that it can't find the file, so I know that Xcode is finding it with #import <XLForm/XLForm.h> .. just not allowing me to use it.
Any suggestions?
EDIT: I've tried including another library and I'm experiencing the same issue. Are there any other steps to using the Bridge Header?
Using
import XLForm
Resolved the problem.