Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"unknown type name import" error in iOS

Tags:

ios

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
}

enter image description here

like image 330
B.Saravana Kumar Avatar asked Jan 07 '16 11:01

B.Saravana Kumar


3 Answers

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.

enter image description here

Let's try above KJTreeObjC.Swift file inside below Objective-C ViewController.

enter image description here


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.
enter image description here

That's the header name we will Import now.
You can check afterwards, error would've been gone instantly.

enter image description here

like image 122
Kiran Jasvanee Avatar answered Sep 23 '22 00:09

Kiran Jasvanee


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"
like image 33
Chowdhury Md Rajib Sarwar Avatar answered Sep 23 '22 00:09

Chowdhury Md Rajib Sarwar


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.

enter image description here

like image 20
Amal T S Avatar answered Sep 25 '22 00:09

Amal T S