Reputation: 1113
I am trying to follow this NSTableView tutorial. I am using Xcode 7.3.1. When it comes time to create the table controller class and make it conform to NSTableViewDataSource (around 5:11 in the video) is when I run into a problem. As I try to type NSTableViewDataSource within the <>, it does not appear in the autocomplete, and if I put NSTableViewDataSource in manually, I get "No type or protocol named 'NSTableViewDataSource'". I can't figure out why this is. The tutorial was created with Xcode 5, and things are different in Xcode 7. I created the class by going to File > New > File. There is no "Objective C Class" option in Xcode 7, so I choose "Cocoa Class" under OS X. I made it a subclass on NSObject like in the video, and called it TableController. I then attempted to make it conform to NSTableViewDataSource, where I ran into the problem. What am I doing wrong? Do I need to create the class in a different way?
Upvotes: 1
Views: 1041
Reputation: 1113
Simply importing Cocoa.h into the TableController class solves the problem. The reason it worked in Xcode 5 in the tutorial is because Xcode 5 (and probably older versions as well) created a pch file that imported Cocoa.h into every source file, therefore eliminating the need to import it into the TableController class manually. It seems that starting with Xcode 6, a pch file is no longer created with new projects, which is why you have to manually import Cocoa.h into the class. You import Cocoa.h by simply putting #import <Cocoa/Cocoa.h>
either above or below the Foundation import line in the new class.
Upvotes: 3