views:

264

answers:

2

Hi there,

I need to reload a Person NSManagedObject before I pass it onto the next View.

This is because the fetchedResultsController I'm using is only returning a subset of attributes and I need the full set in the next view.

Thus far I'm trying something like:

- (void)tableView:(UITableView *)tableViewPassed didSelectRowAtIndexPath:(NSIndexPath *)indexPath {        
        Person *partialPerson = (Person *)[self.fetchedResultsController objectAtIndexPath:indexPath];

   NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:[partialPerson.managedObjectContext]];

    NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
    [request setEntity:entity];
...

Now I can't seem to get the predicate to do this working correctly so far I've tried:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF == %@", partialPerson];

and

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF == %@", partialPerson.objectID];

But neither of these seem to work. What am I doing wrong here? Is this a good approach?

Thanks in advance for any suggestions, Matt

+1  A: 

You just need to access the attributes that are not faulted and they will get faulted automatically. You do not need to refetch the object at all.

Update

Storing images or any binary data in Core Data has some basic rules to follow:

< 100kb store it in the same entity
< 1 mb store it in a separate entity on the other end of a relationship
> 1 mb store it on disk and reference it in the same entity

Sounds like you are storing too much binary data in the primary table. To correct this follow the rule above and it will solve your problem.

But that does not negate my original answer in that you can instruct your fetch to pull in attribute1, attribute3 and attribute 5 and when you need to access attribute3, you just access it and Core Data will "do the right thing" and load it when you try and access it. There is never a reason to "reload" the object in this situation.

Marcus S. Zarra
Hi Marcus,Thanks for your reply. The reason I was trying it this way was to solve a performance issue.My model contains string fields together with an image field that stores photos taken by the users camera. There can be many rows and loading them initially is fairly slow on the device. Sometimes several seconds.If I restricted my fetchRequest (via setPropertiesToFetch) and excluded the image field then the resulting speedup is upwards of 10x faster.However this introduces the need to "reload" the record. Do you have any suggestions for this type of performance problem?Thanks, Matt
Sway
Marcus, Thanks again. I wasn't aware of those Core Data restrictions. I will have to amend my model asap. Cheers, Matt
Sway
A: 

Why you need to refetch partialPerson?

Simply pass it to the next view and you are done!!! You can do all you want with partialPerson variable on the next view. I don't see any reason why you need to refetch it.

myViewController.myPartialPerson = partialPerson;
sfa