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
Project-Swift.h file not found
Project-Swift.h
is a file auto generated by Xcode on successful compilation of the project. Catch here is the word successful compilation If your project has any compilation error Project-Swift.h
file will not be generated. So in a way it becomes a deadlock. Bestway comment out all the lines that have compilation error and then manage to get it compile without any errors. Only after that Project-Swift.h
will be generated.
Additional information, Once the Project-Swift.h
file is generated if you open it and if you happened to see that your swift class is not imported there thats because Project-Swift.h
imports only the classes that extends from NSObject So plain Swift classes will not be imported.
ISSUE:
You need to import Project-Swift.h
in .m file and not .h file. So modify your Blakey as
#import
#import "Blakey.h"
#import "MyProject-Swift.h"
@implementation Blakey
- (void)createKeyPairForSeed:(NSString *)seed;
{
}
Finally remove #import "MyProject-Swift.h"
from Blakey.h
@import Foundation;
@class KeyPair;
@interface Blakey: NSObject
- (void)createKeyPairForSeed:(NSString *)seed;
@end
import swift class in objective-c, -Swift.h file not found
Updated May 2018 Xcode 9.3
- 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"
(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
)
Related Topics
How to Locate the Cgrect For a Substring of Text in a Uilabel
Allow Only Numbers For Uitextfield Input
How to Upload Images to a Server in iOS With Swift
Command Failed Due to Signal: Segmentation Fault: 11
Swift - How to Get the File Path Inside a Folder
How to Determine If an Annotation Is Inside of Mkpolygonview (Ios)
Closure Cannot Implicitly Capture a Mutating Self Parameter
Sharing Data in Between Apps in Ios
How to Detect Collision in Swift, Sprite Kit
Uitableview Cell Selected Color
Enabling Auto Layout in iOS 6 While Remaining Backwards Compatible With iOS 5
How Does View Controller Containment Work in iOS 5
Are There APIs For Custom Vibrations in Ios
How to Pass Data Using Notificationcenter in Swift 3.0 and Nsnotificationcenter in Swift 2.0
Drawing a Route in Mapkit in Ios
Swiftui | Using Ondrag and Ondrop to Reorder Items Within One Single Lazygrid
Fatal Error: Use of Unimplemented Initializer 'Init(Coder:)' For Class