Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top