Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift usage #18

Open
jeff-h opened this issue Jul 9, 2014 · 6 comments
Open

Swift usage #18

jeff-h opened this issue Jul 9, 2014 · 6 comments

Comments

@jeff-h
Copy link

jeff-h commented Jul 9, 2014

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
Copy link
Author

jeff-h commented Jul 12, 2014

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
    }


}

@amalmansouri
Copy link

Can you show your "ContentViewController.Swift" Code please

Many Thanks 👍

@jeff-h
Copy link
Author

jeff-h commented Oct 14, 2014

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.

@amalmansouri
Copy link

Thanks Jeff, I'll check it out.

@amalmansouri
Copy link

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

@olegsfinest
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants