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

SOLVED : Hacking with macOS - Project 1 - Xcode 12/Swift 5

Forums > Books

Stumbling through this first project and looking at all the forum posts on this topic, I have set this up a number of times and keep getting "*** Illegal NSTableView data source (<NSScrollView: 0x7fa478017a00>). Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:"

When I run my code (below) I just get a split table, but nothing on the "left" side like "Table Cell View". In fact, I pulled the "completed" sources and rebuilt them and still get the same error message.

It seems that the previous posts with the same issue may be on Swift 4, but has anyone seen this on Swift 5 (Xcode 12) on Big Sur (11.2.3)? Maybe things are out of date now and I'm just doing something totally dumb?

Full code:

class SourceViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {

@IBOutlet var tableView: NSTableView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do view setup here.
}    

func numberOfRows(in tableView: NSTableView) -> Int {
    return 30
}

}

1      

Ok, this is a real newbie (i.e., embarassing) issue that I found by mucking around LONG enough and looking at exactly what each of the objects attributes were (right click on all the objects in the document outline and comparing to that of the "solution"). Specifically, the "Source View Controller" was missing the 2 Referencing Outlets for the View Table.

Deal is that the text says "Before we’re done with the table view, we’re going to make two further changes. Select “Table View” in the document outline, then Ctrl-drag from there to “Source View Controller”. When you release, choose “dataSource” from the menu that appears. Now do the same thing again, this time choosing “delegate” from the menu."

The problem is the "...from there to "Source View Controller". If the View Table in Source View Controller is highlighted then, in the IB, the visual target consists of a "header" (contains a blue circle surrounding a white square which highlights as "Source View Controller", a brown box which highlights as "First Responder") and a "body" which just has "Table View..." text. The unfortunate (for me) thing was that when I started doing the Ctrl-darg, the "body" highlighted, so that's the destination I used for the "Ctrl-drag". That was wrong. It target should have been the blue circle with a white square in the header. Once I did that, all of the attributes for the Source View Controller now contained the missing Referencing Outlets.

Of course, NONE of this is really evident from the code (I've been coding since IBM 360 card days, on just about a zillion different languages), but is totally relient upon what the IB "helps" with. I've always been a bit leery of graphical code editors, but I guess I should get out of the 1970's and take my lumps.

2      

Save 50% in my WWDC23 sale.

SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.