Alright, so when I first started reading about Xcode and interface builder I followed a few tutorials that made use of AppDelegate.Swift for all UI events. I'm branching out now and trying to make a custom class that still updates labels and windows as I had done in AppDelegate.
I've tried adding the @IBOutlet label to the top of the class however I'm not able to make the connection with my program. I'm trying to update NSPopUpButton, serialListPullDown.
Is there another way of doing this?
import Foundation
import Cocoa
class Serial {
init() {
}
@IBOutlet var serialListPullDown : NSPopUpButton!
func refreshSerialList(defaultprompt: String) {
//Initialize ORSSerialPortManager
let portManager : ORSSerialPortManager = ORSSerialPortManager.sharedSerialPortManager()
var availablePorts : NSArray = portManager.availablePorts
//Erase entries from popup field
serialListPullDown?.removeAllItems()
for port in availablePorts as [ORSSerialPort] {
//Add ports to popup window
var Port = "\(port.path)"
serialListPullDown?.insertText(Port)
}
}
}
Your problem is in IB, making the connection, not the code in the class.
Create an object for your
Serial
class in IB, change its class in the inspector toSerial
, and ctrl-drag to wire up your control.