Learn how to use common macOS UI controls like NSTextField, NSComboBox, NSButton, and more in this two-part series — updated for Xcode 8.2 and Swift 3!
As far as I can tell I’ve got the following set up as instructed:
class ViewController: NSViewController {
@IBOutlet weak var pastTenseVerbTextField: NSTextField!
@IBOutlet weak var singularNounCombo: NSComboBox!
@IBOutlet weak var pluralNounPopup: NSPopUpButton!
@IBOutlet weak var phraseTextView: NSTextView!
fileprivate let singularNouns = ["dog", "muppet", "ninja", "pirate", "dev"]
fileprivate let pluralNouns = ["tacos", "rainbows", "iPhones", "gold coins"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
pastTenseVerbTextField.stringValue = "ate"
singularNounCombo.removeAllItems()
singularNounCombo.addItems(withObjectValues: singularNouns)
singularNounCombo.selectItem(at: singularNouns.count-1)
pluralNounPopup.removeAllItems()
pluralNounPopup.addItems(withTitles: pluralNouns)
pluralNounPopup.selectItem(at: 0)
phraseTextView.string = "Me coding Mac Apps!!!"
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
However, when I run it I get the following error:
2017-10-24 16:01:48.724212-0700 MadLibs[23164:10232020] -[NSScrollView setString:]: unrecognized selector sent to instance 0x6080001c0780
2017-10-24 16:01:48.724330-0700 MadLibs[23164:10232020] Failed to set (contentViewController) user defined inspected property on (NSWindow): -[NSScrollView setString:]: unrecognized selector sent to instance 0x6080001c0780
The error disappears if I remove the “phraseTextView.string = …” line.
This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]
This post has now been updated for Xcode 10.3 and Swift 5!
As a result, the associated forum topic has been re-opened for questions and comments, thanks @rwenderlich.
Note: I’m slowly working on updating macOS dev related posts, if you have any suggestions for which to do next, message me directly.