26. Silver Challenge

Hey, I’m not quite sure that my solution is correct (looks way too simple to me after reading the others), but it seems to be working though… I’d be glad to read some comments on the solution.

///ViewController.swift
...

@IBAction func speakButtonClicked(_ sender: NSButton) {
	if speechSynthesizer.isSpeaking {
	//does nothing
	} else {
		if let contents = textView?.string, !contents.isEmpty{
		speechSynthesizer.startSpeaking(contents)
		} else {
		speechSynthesizer.startSpeaking("The document is empty")
		}
	}
}

@IBAction func stopButtonClicked(_ sender: NSButton) {
	if speechSynthesizer.isSpeaking {
          speechSynthesizer.stopSpeaking()
	}
}

Well you need to set the isEnabled to true/false for the speak and stop buttons as well, that is what the challenge is about.