0

I know that if I want to use Objective-C classes in Swift, I have to use the bridging header. I know that I can use Objective-C and C++ in the same file via the .mm extension.

Now can I have a file that uses a class written in Objective-C++ and import it into a Swift based project via the bridging header?

I know a similar question that has been asked on Stack Overflow, but the user asked if he/she can use Swift and C++ in the same FILE, not project via a bridging header.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Harshil.Chokshi
  • 671
  • 15
  • 26

1 Answers1

0

Ok I feel really foolish right now, but I should have tried it instead of just asking it on Stack Overflow and expecting an answer. It isn't that I am lazy but I got so used to asking questions on Stack Overflow that my instinct is to ask a question on Stack as soon as I have a problem instead of trying to find the solution myself first.

Answer:

Yes it works! You can use an Objective-C++ class in Swift via the bridging header. Now I didn't do anything to complicated, just implemented a method in Objective-C++ class and included the file in the bridging header and called the method in ViewController.Swift and it worked perfectly fine. I do not know whether all C++ syntax will work perfectly with Swift classes, but i guarantee it most should. So final answer is that yes it works!

Harshil.Chokshi
  • 671
  • 15
  • 26