AXStatusItemPopup
AXStatusItemPopup copied to clipboard
Swift usage
I'm wondering if you could give a quick example of how to use this from inside Swift? I have created the MyProject-Bridging-Header.h containing #import "AXStatusItemPopup.h" and can now do the following:
var image = NSImage(named: "cloud")
var altImage = NSImage(named: "cloudgrey")
var myPopup = AXStatusItemPopup()
but that's as far as I can work out. Xcode's autocomplete suggests the following, which makes no sense to me and doesn't seem to align with any of the methods defined on AXStatusItemPopup:
myPopup.view(<#view: NSView?#>, stringForToolTip: <#NSToolTipTag#>, point: NSPoint, userData: <#CMutableVoidPointer#>)
I got this to work. If anyone else is having trouble getting this to work from Swfit, drop a comment here and I'll try to help. The basics were:
- create a
ContentViewController.swiftand 'ContentViewController.xibsimilar to the AXStatusItemPopup demo. - make sure the bridging header is created, as per my initial question above.
- I have this in my
AppDelegate.swift:
class AppDelegate: NSObject, NSApplicationDelegate {
var statusItemPopup: AXStatusItemPopup?
@IBOutlet var window: NSWindow
@IBOutlet var showPopupBtn: NSButton
@IBAction func showPopupBtnAction(sender: NSButton) {
statusItemPopup?.showPopoverAnimated(true)
}
func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
// init the content view controller
// which will be shown inside the popover.
var myContentViewController = ContentViewController(nibName: "ContentViewController", bundle: NSBundle.mainBundle())
// init the status item popup
var image = NSImage(named: "cloud")
var alternateImage = NSImage(named: "cloudgrey")
statusItemPopup = AXStatusItemPopup(viewController: myContentViewController, image: image, alternateImage: alternateImage);
// Set the popover to the contentview to e.g. hide it from there.
myContentViewController.statusItemPopup = statusItemPopup;
}
func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}
}
Can you show your "ContentViewController.Swift" Code please
Many Thanks :+1:
Hi — feel free to check out the whole project where I have used AXStatusItemPopup inside Swift: https://github.com/jeff-h/duckdns
It's a work-in-progress as I learn Swift, but the popup part of the project works fine.
Thanks Jeff, I'll check it out.
Very Nice and clean solution :+1: I have already implement it to my project and it's working like a charm
thank you so much @aschuch, @jeff-h , I have been searching a long time for a solution in swift and this one does it for me.