I'm just looking for some advice here regarding decoupling of view from model. I have a BLE class which does its thing and i instantiate it naturally in the main View Controller. One of the things application does is just display some of information from a scan in a text field. I want to update the view as soon as the delegate method fires in the BLE class, the only way I could think to acheive that was to pass in a reference to the text field as part of the constructor. Then I can just dispatch a request to the main thread to update my view.
class BLEScanner: NSObject, CBCentralManagerDelegate {
var central: CBCentralManager?
var peripherals : [(CBPeripheral,Int)] = []
var scanOutput: NSTextField?
init(scanOutput: NSTextField) {
self.scanOutput = scanOutput
super.init()
let centralQueue = dispatch_queue_create("sup", DISPATCH_QUEUE_SERIAL)
central = CBCentralManager(delegate: self, queue: centralQueue)
}
This doesn't really seem right to pass a reference to a text field, is there a better way to do this?