NSViewController subclass troubles

274 views Asked by At

I have created a NSCollectionViewItem subclass, called TSCollectionViewController. It overrides one method, setRepresentedObject:. I plan on using it in my NSView, TSTopChartView. Oddly enough, I get an error when I add it to the TSTopChartView.h file (pictured below). enter image description here enter image description here

Obviously, Xcode doesn't like TSCollectionViewController for this file. I just can't figure out why! I've imported the file, so it shouldn't be an unknown type name. Any ideas? Thank you for your time!

Here is TSCollectionViewController.h:

#import <Cocoa/Cocoa.h>
#import "TSTopChartCell.h"
#import "TSPodcastEpisodeCell.h"
#import "TSDetailView.h"

@interface TSCollectionViewController : NSCollectionViewItem
@end
1

There are 1 answers

0
torrey.lyons On BEST ANSWER

You have a circular #import dependency between TSCollectionViewController.h and TSTopChartView.h. In your case you can break it easily by removing #import "TSTopChartCell.h" from TSCollectionViewController.h.

If you end up in a case where you really need the class TSTopChartCell to be declared in TSCollectionViewController.h you can fix this by adding @class TSTopChartCell instead of the #import "TSTopChartCell.h". Then you can actually #import "TSTopChartCell.h" in the implementation file, TSCollectionViewController.m.