Wiring actions in Playground live view (macOS)?

I can't find any comprehensive documentation on how to use Playground live views in Xcode 9.


My current question (aside from just getting basic changes to the NIB to show up) is: how do I connect an NSButton to an @IBAction in my Playground file? I guess I have to provide an owner object?


I tried doing as much, but Xcode complains (even though it lets me drag from the view to my owner object): "Could not insert new action connection: Could not find any information for the class named Scanner"


Code:


import AppKit
import PlaygroundSupport
let nibFile = NSNib.Name(rawValue:"MyView")
var topLevelObjects : NSArray?
let scanner = Scanner()
Bundle.main.loadNibNamed(nibFile, owner:scanner, topLevelObjects: &topLevelObjects)
let views = (topLevelObjects as! Array<Any>).filter { $0 is NSView }
/
PlaygroundPage.current.liveView = views[0] as! NSView
/ 
import ImageCaptureCore
class
Scanner
  : NSObject
{
  func
  findScanner()
  {
  self.scannerBrowser.delegate = self
  self.scannerBrowser.browsedDeviceTypeMask = ICDeviceTypeMask(rawValue:
            ICDeviceLocationTypeMask.local.rawValue |
                ICDeviceLocationTypeMask.shared.rawValue |
                ICDeviceLocationTypeMask.bonjour.rawValue |
                ICDeviceLocationTypeMask.remote.rawValue |
                ICDeviceLocationTypeMask.bluetooth.rawValue |
  ICDeviceTypeMask.scanner.rawValue)!/
  self.scannerBrowser.start()
  }

  var scannerBrowser = ICDeviceBrowser()
}
...

Replies

LOL..I'm searching for how to use macOS Playgrounds as well. This post is the only thing I can find. Is it possible that it's just a broken thing in XCode that nobody uses?


I can't even get it to find any custom class I create so it looks like you got further than I did.