solo
solo

Reputation: 783

Making NSView appearance vibrantDark

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.

Upvotes: 2

Views: 1244

Answers (1)

l'L'l
l'L'l

Reputation: 47169

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

Upvotes: 1

Related Questions