2

I'm currently learning Swift, and I followed this tutorial to create an NSWindow that inherits the vibrantDark property from the AppKit in Swift. The code I added to the WindowController.swift file is as follows:

window?.titleVisibility = .hidden
window?.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark)

What I'd like to do is achieve the same result for an NSPopover in my program; however, when I add the following to my LogViewController.swift file, I get an error -- the first of which is "Value of type 'NSView' has no member 'titleVisibility,'" and the second of which is "Cannot use optional chaining on non-optional value of type 'NSView.'"

view?.titleVisibility = .hidden
view?.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark)

Several posts have addressed this issue for NSWindow, but I cannot find an answer that addresses NSPopover. I currently have the following condition set to open NSPopover upon clicking NSImage in the status bar:

popover.contentViewController = LogViewController.freshController()

I'm thinking that having NSPopover as NSView is what's causing the issue, but -- being as I'm still new to Swift -- I'm not sure how to diagnose this the problem. That said, I would much appreciate it if anyone could point me towards the right direction.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
solo
  • 743
  • 2
  • 6
  • 17

1 Answers1

1

You should be using an NSPopover, not an NSView:

var myPopover: NSPopover?

myPopover = NSPopover.init()
myPopover?.appearance = NSAppearance(named: .vibrantDark)

If you want to use a contentViewController:

var popoverViewController: NSViewController?

myPopover?.contentViewController = self.popoverViewController
l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • `NSAppearance.Name` is redundant. `myPopover?.appearance = NSAppearance(named: .vibrantDark)`. Btw please don't use semicolons in Swift – Leo Dabus Dec 22 '17 at 01:44
  • @LeoDabus In which file should I be putting this? – solo Dec 22 '17 at 03:05
  • 1
    @rrod those are specific NSWindow properties. NSView has no appearance or titleVisibility properties. You can try setting your view window property `view.window?.whatever` as long as the window property it is not nil (try in viewDidAppear method) – Leo Dabus Dec 22 '17 at 03:24