title: NSPopover in Mac Catalyst for Mac menu bar
body: <p>I am trying to add a MenuBar Item to my Mac Catalyst app.</p>
  <p>I have successfully made the iPad app work on Mac, but adding the MenuBar item is turning out to be quite difficult.</p>
  <p>I have tried solving the issue using the following two links, but they don't have a GitHub repo which I can look at, and the explanations do some jumps.</p>
  <p><a href="https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit" rel="nofollow noreferrer">https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit</a>
  <a href="https://developer.apple.com/documentation/xcode/creating_a_mac_version_of_your_ipad_app" rel="nofollow noreferrer">https://developer.apple.com/documentation/xcode/creating_a_mac_version_of_your_ipad_app</a></p>
  <p>Right now I have the following code in my AppDelegate:</p>
  <pre><code>#if targetEnvironment(macCatalyst)
      import AppKit
      import Cocoa
  
  #endif
  import UIKit
  import CoreData
  
  @UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate {
      
      #if targetEnvironment(macCatalyst)
          var popover: NSPopover!
          var statusBarItem: NSStatusItem!
      #endif
  
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
          // Override point for customization after application launch.
          
          #if targetEnvironment(macCatalyst)
          // Code to include from Mac.
          #endif
          #if targetEnvironment(macCatalyst)
              let contentView = MenuBarView()
  
              // Create the popover
              let popover = NSPopover()
              popover.contentSize = NSSize(width: 400, height: 500)
              popover.behavior = .transient
              popover.contentViewController = NSHostingController(rootView: contentView)
              self.popover = popover
              
              // Create the status item
              self.statusBarItem = NSStatusBar.system.statusItem(withLength: CGFloat(NSStatusItem.variableLength))
              
              if let button = self.statusBarItem.button {
                  button.image = NSImage(named: &quot;MenuBar&quot;)
                  button.action = #selector(togglePopover(_:))
              }
          #endif
          
          return true
      }
      
      #if targetEnvironment(macCatalyst)
          @objc func togglePopover(_ sender: AnyObject?) {
               if let button = self.statusBarItem.button {
                    if self.popover.isShown {
                         self.popover.performClose(sender)
                    } else {
                         self.popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
                          self.popover.contentViewController?.view.window?.becomeKey()
                    }
               }
          }
      #endif
      
      
      func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
          
          guard let windowScene = (scene as? UIWindowScene) else { return }
          
          #if targetEnvironment(macCatalyst)
          if let titlebar = windowScene.titlebar {
              titlebar.titleVisibility = .hidden
              titlebar.toolbar = nil
          }
          #endif
  
      }
  
  ...more code from CoreData
  </code></pre>
  <p>The Errors that is is showing
  <img src="https://i.stack.imgur.com/h5L5c.png" alt="The Errors that is is showing" /></p>
  <p>I am really new to iOS development and I am getting really lost, so any and every help is really appreciated.</p>
  <h3>Edit</h3>
  <p>Yes, the screenshot is from the AppDelegate.</p>
  <p>I am trying to implement something like this:
  <a href="https://github.com/AnaghSharma/Ambar-SwiftUI" rel="nofollow noreferrer">https://github.com/AnaghSharma/Ambar-SwiftUI</a></p>
  <p>every implementation that I have seen thus far put this into the AppDelegate, which is why I am trying to do the same thing as well.</p>