1

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.

3
  • See How do I call Objective-C code from Swift? Commented Nov 2, 2022 at 19:21
  • Yes thank you that what I did, I have edited the post to add more precision about my problem Commented Nov 3, 2022 at 8:25
  • Not sure to understand your need but Apple states : « source code intended to run only in macOS, use #if TARGET_OS_MACCATALYST instead.» Commented Nov 3, 2022 at 16:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.