WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Need help getting TableView to properly display

Forums > macOS

Hello! I am working through the 1st Hacking with macOS project and have hit a pesky road block when attempting to get tableView to work in SourceViewController. I wrote the method to return number of rows but when I build the project I do not see my table. I'm not sure where I'm going wrong here but any guidance is much appreciated.

import Cocoa

class SourceViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
    @IBOutlet var tableView: NSTableView!

    override func viewDidLoad() {
        // Do view setup here.
    func numberOfRows(in tableView: NSTableView) -> Int {
        return 100


Did you control-drag from the Table View to the SourceViewController in the storyboard outline? This is described on page 135 of the PDF version of the book. You have to do it twice to connect the SourceViewController to the TableView as its dataSource and its delegate.

To verify you succeeded, select the SourceViewController in the storyboard outline and press ⌥⌘7 to show the Connections Inspector. Under Referencing Outlets, tableView should be listed twice, as dataSource and delegate.


Bob's answer might be the best answer of 2022 (so far) for why Obelix doesn't want to learn UIKit and Interface Builder.



Double checked and I do have the the Source View Controller connected properly. I've attached a screenshot below. When I run my build I get a black window with an adjustable split view but no (visible) "table cell view" text indicating my table is properly loading. There is a problem somewhere but my newbie skills are making it hard to debug.



Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.