I Had tried to include swift ViewController File in to Objective-C project but i unable to do it, it shows error like unknown type name import how to solve this please any one help for this issue.
Here I Send my Code and ScreenShot.
import UIKit
@objc class SigViewController2: UIViewController {
@IBOutlet weak var cameraBtn: UIButton!
@IBOutlet weak var imageBtn: UIButton!
@IBOutlet weak var settingsBtn: UIButton!
@IBOutlet weak var mediaBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
navigationController?.navigationBarHidden = false
self.navigationItem.title = "Main";
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
// Only allow Portrait
return UIInterfaceOrientationMask.Portrait
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
// Only allow Portrait
return UIInterfaceOrientation.Portrait
}
For Developers still looking for answer.
Importing Swift
file inside Objective-c
can cause this error, if it doesn't import properly.
Let's look at the the error first.
Let's try above KJTreeObjC.Swift
file inside below Objective-C ViewController
.
Solution:
You've to import it with the help of bridging header.
When you Created/Copied Swift file inside Objective-C project. It would've created a bridging header automatically.
Check Objective-C Generated Interface Header Name
at Targets -> Build Settings
.
That's the header name we will Import
now.
You can check afterwards, error would've been gone instantly.
This error is showing because you have imported .swift
class in your Objective-C ViewController
. This is wrong and you should import Swift header, instead:
#import "ProductModuleName-Swift.h"
In my case, it was because somehow the selected type in the file inspector was objective-c source instead of Default - Swift Source even though i was using a .swift file.
Changing it to Default - Swift Source solved the issue for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With