Swift Bridging-Header.h file not allowing me to instantiate objective-c classes in .swift files
You need to add it to your target's build settings:
In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.
Set "Objective-C Bridging Header" to
<#PROJECT_NAME>-Bridging-Header.h
I'm not sure of the correct value for "Install Objective-C Compatibility Header", but it's a yes/no, so you can toggle that if it doesn't work at first.
Trouble with Swift's Bridging-Header.h
You are missing an import. Add the following to your Objective-C Header:
#import <CoreData/CoreData.h>
Swift bridging header file won't work with use_frameworks
A) Create a Bridging Header file named
"ProjectName-Bridging-Header.h" in the root folder of your project.
B) Go to the project build settings and set the following values:
- "Install objective-c compatibility header" : YES
- "Objective-C Bridging Header" : path of your bridging header (e.g. "ProjectName/ProjectName-Bridging-Header.h"
After that you can use the header file to import all your ObjectiveC files which you want use within swift code.
NOTE: if required set the path as a recursive both in the resource headers and the Swift compiler search section.
Xcode not automatically creating bridging header?
The reason of your issue is, the Xcode build settings still holds the path to auto generated Bridging Header file. You cannot get any build errors because of the header file (ProjectName-Bridging-Header.h)
still exist in your project directory.
How to resolve:
Click on your project target, Go to Build Settings tab (choose all instead of basic), search for Bridging Header. You can see the Xcode generated path entry. Select it and click on delete button.
Also, make sure to delete the Xcode auto generated bridging header file (ProjectName-Bridging-Header.h)
from your Xcode project directory.
Now, try to import the Obj-C file once again. You can see the prompt to create a bridging header file as expected.
Importing Project-Swift.h into a Objective-C class...file not found
I was running into the same issue and couldn't get my project to import swift into obj-c classes. Using Xcode 6, (should work for Xcode 6+) and was able to do it in this way....
- Any class that you need to access in the .h file needs to be a forward declaration like this
@class MySwiftClass;
- In the .m file ONLY, if the code is in the same project (module) then you need to import it with
#import "ProductModuleName-Swift.h"
Link to the apple documentation about it
https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c
Related Topics
How to Disable Calayer Implicit Animations
How to Know If Nsassert Is Disabled in Release Builds
New Foursquare Venue Detail Map
How to Determine Device Type from Swift? (Os X or iOS)
How to Capture Picture with Avcapturesession in Swift
How to Add a Toolbar to the Bottom of a Uitableviewcontroller in Storyboards
Align Button Image to Right Edge of Uibutton
iOS Get Heart Rate from Apple Watch in Near Real Time
Space Between Sections in Uitableview
How to Keep an Iphone/iPad Web App in Full Screen Mode
Can't Set Headers on My Wkwebview Post Request
Connect to Vpn Programmatically in iOS 8
How to Stop Firebase from Logging Status Updates When App Is Launched
Swift:Missing Argument Label 'Xxx' in Call
Uisearchbar Change Placeholder Color