1

I am trying to add objective c view controller in the swift project.so some help me out solve this.

    let objCObject = SampleClass()   //   objectiv C object Class
    objCObject.run

    let objCObject1 = SampleViewController() // objective C viewcontroller
    objCObject1.run

Thanks for quick response.

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Gopi Ch
  • 73
  • 1
  • 8

2 Answers2

1

Make one .h file and import all objective c files like Myfile.h into that Header file just you make.

Now into build settings, Find Objective-C Bridging Header and give path of this file

Now you can use any Objective-C file into Swift

Hope this will helps

Dheeraj D
  • 4,386
  • 4
  • 20
  • 34
Jitendra Modi
  • 2,344
  • 12
  • 34
0

You can use Bridging Header. Here are the steps to do that.

Click on your project target, Go to Build Settings tab, search for Bridging Header. You can see the Xcode generated path entry.

Select it and click on delete button.

Also, make sure to delete the Xcode auto generated Bridging Header file ProjectName-Bridging-Header.h from your Xcode project directory.

Now, try to import the Objective-C file once again. You can see the prompt to create a Bridging Header file as expected.

enter image description here

Dheeraj D
  • 4,386
  • 4
  • 20
  • 34
Sivajee Battina
  • 4,124
  • 2
  • 22
  • 45