Importing Swift file to Objective-C project
28 Jun 2017 I think it is very complex when I read Apple's reference. Hence, I decided to write a simple article which illustrates you how to import Swift file into Objective-C project step by step.First, you should create an Objective-C project.
After project be created. We have some parameters should be set in Build Settings.
New or add exist Swift file into the project. Then Xcode pop-ups a dialog, follows image. We just click “Create Bridging Header” to automatically crate bridging header. After that, we can see the bridging header file which be names your product name followed by adding "-Bridging-Header.h".
Finally, we need to import “MixDemo-Swift.h” to any Object-C .m. That header is created by Xcode, but you cannot see in the project folder. The file names your Product Module Name, which we mentioned above, followed by add “-Swift.h”. You can also search "Objective-C Generated Interface Header Name" under Build Settings.
#import "MixDemo-Swift.h"
Then, we can use swift object in the Objective-C project directly.
BarcodeScannerViewController *barcodeViewController = [[BarcodeScannerViewController alloc] init];
barcodeViewController.delegate = self;
[self presentViewController:barcodeViewController animated:YES completion:nil];
Reference: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html