April 2015
Intermediate to advanced
556 pages
17h 47m
English
At the beginning of this chapter, you saw that the NSSpeechSynthesizerDelegate protocol defines five optional methods. In your delegate, you implemented only one of them, didFinishSpeaking. A delegate does not have to implement an optional method, but if it does, it will get called. In many languages, this sort of thing would be impossible. How is it achieved in Swift?
NSSpeechSynthesizer is a standard Cocoa class written in Objective-C, but if it were written in Swift the implementation might contain something like this:
class NSSpeechSynthesizer { ... weak var delegate: NSSpeechSynthesizerDelegate? ... func startSpeakingString(text: String) -> Bool { // Start speaking ...Read now
Unlock full access