Implementing data source methods - swift 3.0.1

Code converted for Swift 3.0.1 compatibility. I have not completed the entire chapter, but the example is working as described in the book.

// MARK: - NSTableViewDataSource
// original
func numberOfRowsInTableView( tableView: NSTableView) -> Int {
return voices.count }

// Swift 3.0.1
func numberOfRows(in tableView: NSTableView) -> Int {
    return voices.count
}

// original
func tableView( tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? {
    let voice = voices[ row]
    let voiceName = voiceNameForIdentifier( voice)
    return voiceName
}

// Swift 3.0.1
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
    let voice = voices[ row]
    let voiceName = voiceNameForIdentifier( identifier: voice)
    return voiceName as AnyObject?
}

to be complete, I would rename the voiceNameIdentifier to conform to the new Swift naming conventions:

func voiceName(forIdentifier identifier: String) -> String? {
    let attributes = NSSpeechSynthesizer.attributes(forVoice: identifier)
    return attributes[NSVoiceName] as? String

}

BTW this code shows a weird little problem with the new naming convention… You can’t use the variable name voiceName anymore in tableView(_:objectValueForTableColumn:row) . That’s definitely a fail if you ask me.