Search code examples
objective-ccore-datanstableviewnsarraycontroller

Core Data - NSArrayController - ObjectAtIndex


I am developing a core data based application, and have a NSTableView bound to an NSArrayController, which is pulling a core data entity.

I need, in code, to be able to pull a specific object from core data, based on a specific row in the table, i had thought this would be trivial by asking the NSArrayController for the object at a specific index. However it appears that the NSArrayController has no methd for this, which i find very odd.

I could setup a fetch request, but that seems very expensive just to fetch a specific object.

So, am i missng something, or is it really this clunky?

Thanks

Gareth


Solution

  • Assuming you have object (NSManagedObject subclass) called Object,

    - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath(NSIndexPath*)indexPath 
    {
        Object *object = self.arrayController.arrangedObjects[indexPath.row]; 
        // do you drawing, cell setup, etc. after
    }