我只是遇到了一个奇怪的麻烦。我写了一个测试应用程序,搜索min&最大数组值。在第一次应用程序正常工作,但只有一个警告:“Array MinMax [554:5057]无法连接(exitNow)插座(Array_MinMax.ViewController)到(NSButton):缺少setter或实例变量”
现在,几天后,我再次启动应用程序,输入一些值,按下按钮和应用程序立即粉碎同样的错误:
2016-06-15 12:11:40.910 Array MinMax[829:18846] Failed to connect (exitNow) outlet from (Array_MinMax.ViewController) to (NSButton): missing setter or instance variable
(lldb)
以下是代码:
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var inputArrayValues: NSTextField!
@IBOutlet weak var minLabel: NSTextField!
@IBOutlet weak var maxLabel: NSTextField!
@IBAction func exitNow(sender: AnyObject) {
NSApplication.sharedApplication().terminate(self)
}
@IBAction func arrayMinMax(sender: AnyObject) {
let someData: String? = inputArrayValues.stringValue
let separators = NSCharacterSet(charactersInString: " ,;:|")
let parts = someData!.componentsSeparatedByCharactersInSet(separators)
let intArray = parts.map{Double($0)}
let minArray = intArray.minElement({$0 < $1}) // - stops on that line (thread 1: breakpoint 1.1)
let maxArray = intArray.maxElement({$0 < $1})
let minString = String(minArray!)
let maxString = String(maxArray!)
minLabel.stringValue = "The minimal value is \(minString)!"
maxLabel.stringValue = "The maximal value is \(maxString)!"
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
}
该怎么办,我无法理解!这是Xcode 7.3.1的错误吗?
答案 0 :(得分:0)
已经解决了这个麻烦。只需使用“NSButton”而不是“Any Object”重新创建按钮。然后,错误就消失了!