简体   繁体   中英

Can I import Objective-C++ classes in a Swift based project using bridging header?

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM