Cannot import Objective C++ wrapper class into my Swift code

I have an Objective C++ wrapper class called ImageDividerWrapper in which there is a function I want to use in a Swift class called FrameProcessor.

Inside the ImageDividerWrapper.h file I made sure to import the bridging header. I also double-checked that the bridging header was referenced and spelled correctly in Project/Build Settings/Swift Compiler. I also deleted derived data, cleaned build folder, etc..

Also imported ImageDividerWrapper.h into my bridging header file:

#import "ImageDividerWrapper.h"

And in my ImageDividerWrapper header file I include:

#import "Vsn3-Bridging-Header.h"

Unfortunately, I still continue to get the error: "No such module 'ImageDividerWrapper'" when trying to directly import the Objective C++ class into my Swift file with:

import ImageDividerWrapper

If anyone who has solved this problem before can point me in the right direction, I would appreciate it so much!

Thank you!

Replies

Unfortunately, I still continue to get the error: No such module 'ImageDividerWrapper' when trying to directly import the Objective C++ class into my Swift file with:

import ImageDividerWrapper

If you’re using a bridging header you don’t need to import a module in your Swift code. Stuff you import in the bridging header is available to any Swift code in your app. So, you should be able to just use ImageDividerWrapper directly.

If ImageDividerWrapper isn’t being imported into Swift, it’s likely there’s some aspect of it that Swift doesn’t like. I usually investigate such problems by creating a new empty class and see if that imports. If it does, I add stuff until I work out what’s causing the import problem.

ps Things are changing with regards Swift and C++ integration. For the details, check out WWDC 2023 Session 10172 Mix Swift and C++. However, you don’t need the new stuff to solve this problem.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"