I have written a library in Swift and I wasn't able to import it to my current project, written in Objective-C.
Are there any ways to import it?
#import "SCLAlertView.swift" - 'SCLAlertView.swift' file not found
I have written a library in Swift and I wasn't able to import it to my current project, written in Objective-C.
Are there any ways to import it?
#import "SCLAlertView.swift" - 'SCLAlertView.swift' file not found
Go to build settings in your project file and search for "Objective-C Generated Interface Header Name. The value of that property is the name that you should include.
If your "Product Module Name" property (the one that the above property depends on by default) varies depending on whether you compile for test/debug/release/etc (like it does in my case), then make this property independent of that variation by setting a custom name.
Checkout the pre-release notes about Swift and Objective C in the same project
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_75
You should be importing
Search for "Objective-C Generated Interface Header Name" in the Build Settings of the target you're trying to build (let's say it's
MyApp-Swift.h
), and import the value of this setting (#import "MyApp-Swift.h"
) in the source file where you're trying to access your Swift APIs.The default value for this field is
$(SWIFT_MODULE_NAME)-Swift.h
. You can see it if you double-click in the value field of the "Objective-C Generated Interface Header Name" setting.Also, if you have dashes in your module name (let's say it's
My-App
), then in the$(SWIFT_MODULE_NAME)
all dashes will be replaced with underscores. So then you'll have to add#import "My_App-Swift.h"
.Find the .PCH file inside the project. and then add
#import "YourProjectName-Swift.h"
This will import the class headers. So that you don't have to import into specific file.Instructions from the Apple website:
Revision:
You can only import "ProductName-Swift.h" in .m files.
First Step:-
Select Project Target -> Build Setting -> Search('Define') -> Define Module update value No to Yes
"Defines Module": YES.
"Always Embed Swift Standard Libraries" : YES.
"Install Objective-C Compatibility Header" : YES.
Second Step:-
Add Swift file Class in Objective C ".h" File as below
Import 'ProjectName(Your Project Name)-Swift.h' in Objective C ".m" file