The NSTableViewDataSource Protocol

Setting up a data source for a table view follows the same pattern that you saw in Chapter 6 when setting up a delegate for the speech synthesizer. There are three steps: conforming to the protocol, implementing methods from the protocol, and setting the dataSource property.

Conforming to the protocol

In MainWindowController.swift, add the NSTableViewDataSource protocol to the MainWindowController class definition.

import Cocoa

class MainWindowController: NSWindowController, NSSpeechSynthesizerDelegate,
                            NSWindowDelegate {
class MainWindowController: NSWindowController, NSSpeechSynthesizerDelegate,
                            NSWindowDelegate, NSTableViewDataSource {
    ...

Connecting the dataSource outlet

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.