0

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.

  • See [How do I call Objective-C code from Swift?](https://stackoverflow.com/questions/24002369/how-do-i-call-objective-c-code-from-swift?rq=1) – HangarRash Nov 02 '22 at 19:21
  • Yes thank you that what I did, I have edited the post to add more precision about my problem – Jeremy THIRIEZ Nov 03 '22 at 08:25
  • Not sure to understand your need but Apple states : « source code intended to run only in macOS, use #if TARGET_OS_MACCATALYST instead.» – Ptit Xav Nov 03 '22 at 16:54

0 Answers0