I’m trying to create code similar to a post on CIMG re iTunes search field. I’ve looked through the NSPredicate Programming Guide, the Core Data book and numerous ‘net posts, with no success. I’m getting an NSFaultingMutableSet error, which, I think, means that a fault isn’t firing, which means the app doesn’t have access to the data in the relationship, so, it can’t search through the attributes on the related entities. I’ve tried pre-fetching relationships, but, that doesn’t work, either (or, rather, I must not be doing it correctly).
Part of my app is an image library. I have an ImageResource entity to track basic information on each image imported into the library, including its URL. I have another entity, TagForResource with a single string attribute, tagString. An image can have multiple tags and each tag can be related to multiple images.
I have a NSSearchField. Text entered into the search field should build a predicate to filter the images in my array controller. I can filter for attributes on the ImageResource, but, when I try to include:
@”ANY tags.tagString like %@”, searchText
[<_NSFaultingMutableSet 0x2000992e0> addObserver:forKeyPath:options:context:] is not supported. Key path: tagString
Initially, I thought I needed to fire the fault to retrieve the TagForResource objects, so, I added the following to the beginning of my searchFieldChanged method:
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"ImageResourceP" inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; NSArray *relKeys = [NSArray arrayWithObjects:@"tags", nil]; [request setRelationshipKeyPathsForPrefetching:relKeys]; NSError *error = nil; NSArray *relationships = [self.managedObjectContext executeFetchRequest:request error:&error];
but, that didn’t help.
I’ve also tried wiring it through IB, but I get the same results. How can I filter images based on their tag strings?