I am trying to programmatically setup an NSArrayController
to work with Core Data.
I know that my Core Data store has content since I can manually retrieve objects through the managed object context. I hooked up an NSArrayController
to the same managed object context and then bound the value parameter of a NSTableColumn
to the NSArrayController
.
I asked the NSArrayController
to fetch but it returns an empty array.
Any suggestions on what I might be doing wrong?
Interface
@interface MTTableViewController : NSObject <NSTableViewDelegate, NSTableViewDataSource>
{
NSMutableArray *tableData;
MTTableCell *tableCell;
IBOutlet NSTableColumn *tableColumn;
NSArrayController *dataController;
}
Implementation
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
dataController = [[NSArrayController alloc] init];
[dataController setManagedObjectContext:[[NSApp delegate] managedObjectContext]];
[dataController setEntityName:@"Track"];
[dataController setAutomaticallyPreparesContent:YES];
[dataController fetch:self];
NSArray *content = [dataController arrangedObjects];
NSLog(@"Count :%i", (int)[content count]); //Outputs 0
tableCell = [[MTTableCell alloc] initTextCell:@""];
[tableColumn setDataCell:tableCell];
}
return self;
}