I am new to Swift and Mac App. So I am writing a Mac application today, and I am still confused how to access IBOutlet from another class after a lot of searching.
I use StoryBoard and there are two NSTextField in my ViewController path mirror. I created my own class Path.swiftfor the first NSTextField pathto find out when the text in pathchanged.
class Path: NSTextField, NSTextFieldDelegate
{
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
self.delegate = self
}
var current = ""
override func controlTextDidChange(obj: NSNotification)
{
current = self.stringValue
println("Current is \(current)")
}
}
And there are two outputs defined in ViewController.swift
class ViewController: NSViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
}
override var representedObject: AnyObject? {
didSet {
}
}
@IBOutlet weak var path: NSTextField!
@IBOutlet weak var mirror: NSTextField!
}
And when the user enters something into the first NSTextField path, I want the second NSTextField to mirrorshow the same line as path.
I tried to use ViewController().mirror.stringValue = currentbut gotfatal error: unexpectedly found nil while unwrapping an Optional value
, ViewController ViewController.
, , IBOutlet ViewController.swift Path.swift ( ViewController).
.
.