April 2015
Intermediate to advanced
556 pages
17h 47m
English
In this section, you are going to ensure that the Speak and Stop buttons are enabled or disabled at the appropriate times. The first step is to create a new property in MainWindowController that will keep track of whether the speech synthesizer is currently speaking.
In MainWindowController.swift, add the following code.
class MainWindowController: NSWindowController {
...
let speechSynth = NSSpeechSynthesizer()
var isStarted: Bool = false
override var windowNibName: String {
return "MainWindowController"
}
...
Next, adjust the button’s action methods to set this property.
// MARK: - Action methods @IBAction func speakIt(sender: AnyObject) { // Get typed-in text as a string let string = textField.stringValue ...Read now
Unlock full access