John
John

Reputation: 548

Referencing a Swift View Controller from an Objective C View Controller

I can't figure out how to reference a Swift VC from an Objective C VC in a mixed language project. Here is Objective C code:

#import "NamesVC."

...   ([segue.identifier isEqualToString:@"peopleSegue"]){
        NamesVC *vc      = segue.destinationViewController;
        vc.selEntity     = @"People";
        vc.delegateMethod= @"Admin";
        }

Bridging Header: Version10-Bridging-Header.h

#ifndef Version10_Bridging_Header_h
#define Version10_Bridging_Header_h

#import "AppDelegate.h"
#import "AdminTVC.h"

How do you import by Swift VC into the Obj C class?

Upvotes: 0

Views: 1648

Answers (3)

b_the_builder
b_the_builder

Reputation: 69

For anyone not finding a solution changing

"MyApp-Swift.h"  to   <MyApp-Swift.h>

in my objective c .m file that I wanted to reference my swift class

Upvotes: 1

user3182143
user3182143

Reputation: 9609

Importing Swift into Objective-C

You should import the Swift code from that target into any Objective-C .m file within that target using this syntax and substituting the appropriate name:

#import "NamesVC.h"

Upvotes: 0

Nirav D
Nirav D

Reputation: 72460

Import ProjectModuleName-swift.h header inside your .m file where you want to access Swift controller like this.

#import "ProjectModuleName-Swift.h" 

After that you are able to access NamesVC inside your Objective c ViewController.

For more about this read Apple documentation on Swift and Objective-C in the Same Project, inside this doc read about Importing Swift into Objective-C

Upvotes: 2

Related Questions