AXStatusItemPopup icon indicating copy to clipboard operation
AXStatusItemPopup copied to clipboard

Swift usage

Open jeff-h opened this issue 11 years ago • 6 comments
trafficstars

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#>)

jeff-h avatar Jul 09 '14 09:07 jeff-h

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.swift and 'ContentViewController.xib similar 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
    }


}

jeff-h avatar Jul 12 '14 06:07 jeff-h

Can you show your "ContentViewController.Swift" Code please

Many Thanks :+1:

amalmansouri avatar Oct 14 '14 17:10 amalmansouri

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.

jeff-h avatar Oct 14 '14 20:10 jeff-h

Thanks Jeff, I'll check it out.

amalmansouri avatar Oct 15 '14 07:10 amalmansouri

Very Nice and clean solution :+1: I have already implement it to my project and it's working like a charm

amalmansouri avatar Oct 15 '14 17:10 amalmansouri

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.

olegsfinest avatar Mar 18 '15 15:03 olegsfinest