Santo Santo - 2 years ago 135
iOS Question

Load a Swift based ViewController from Objective C class's button action

Note: It is not a duplicate one to any question. I could not find any question with some action method and creating an instance for a swift based view controller.

I am calling a swift based view controller in objective c class .m file.

In my

I have imported bridge header

#import "ViewController.h"
#import "Project-Bridging-Header.h"

I want to call Swift based view controller from the below action

- (IBAction)tappedButnGo:(UIButton *)sender {

SwiftViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SwiftViewController"];

Here I am getting an error

use of undeclared identifier SwiftViewController

and below is swift class

import UIKit

@objc class SwiftViewController: UIViewController {
//so on

and my
is empty.

Can anyone help me on loading
when I click on
Objective C'
s button action?

Answer Source

You need to import following statement in your Controller.h file

#import "ProductModuleName-swift.h"

Here PrductModuleName is your project name

Hope this will help you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download