How to find type in objective-c enclosed by 'TARGET_OS_MACCATALYST' from swift file?

97 Views Asked by At

I'm working on porting an iOS application to macCatalyst. On the macCatalyst version, I constructed an NSToolbar in objective-c because it was the only way I find out to get the position of the NSToolBarItem to present a popover. On the iOS version, I don't need this NSToolbar.

So in my file.h (objc) I have:

#if TARGET_OS_MACCATALYST

...

@interface K_ToolBar_Catalyst_Objc : NSToolbar <NSToolbarDelegate>

...

#endif

In the file.swift, I'm trying to access the class K_ToolBar_Catalyst_Objc:

#if targetEnvironment(macCatalyst)

...

var toolBar: K_ToolBar_Catalyst_Objc!

...

#endif

But I got this error: Cannot find type 'K_ToolBar_Catalyst_Objc' in scope

Everything works correctly when I build on catalyst without #if TARGET_OS_MACCATALYST but I would like to be able to build on IOS as well so I have to add the target #if TARGET_OS_MACCATALYST in the objective-c file but adding #if TARGET_OS_MACCATALYST the build on catalyst does not work anymore.

Any suggestions please? Thank's a lot.

0

There are 0 best solutions below