Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can get reference of Swift AppDelegate from objective c code

My Project is in Swift 3.0 and I am using xCode8.2. I need to import objective C code in my swift project. objective C required app delegate reference. How can I get swift appdelegate reference from my objective C code?

In my objective C file #import "AppDelegate.h" is giving not found error as it is swift AppDelegate

like image 625
Avijit Das Avatar asked Feb 28 '17 10:02

Avijit Das


1 Answers

As Kie already said, you need to #import "<ProductModuleName>-Swift.h" in your Obj-C .m file to get all Swift classes. Here a sample project with what you need https://github.com/aminbenarieb/Researches/tree/master/Swift/Swift_ObjC.

Update: If your can't see Swift files in Objective-C files, make sure you have the Objective-C bridging header, as follows in Apple Documentation:

Importing Objective-C into Swift

To import a set of Objective-C files in the same app target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app.

like image 59
Amin Benarieb Avatar answered Sep 21 '22 10:09

Amin Benarieb