开发者

iPhone, Core Data, Predicate with "self" problem

开发者 https://www.devze.com 2022-12-20 10:08 出处:网络
I need to reload a Person NSManagedObject before I pass it o开发者_StackOverflownto the next View.

I need to reload a Person NSManagedObject before I pass it o开发者_StackOverflownto 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


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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号