I have a search function that I want to search my whole core data database.
I have 4 entities, all of which are subclass of NSManagedObject MedicalCode
.
- (void) loadDatabase
{
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"MedicalCode" inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSError *error = nil;
NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];
}
- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in myArray)
{
NSString *value = [dictionary valueForKey:@"name"];
[searchArray addObject:value];
}
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyListOfItems addObject:sTemp];
}
[searchArray 开发者_如何学Crelease];
searchArray = nil;
}
The problem here is that, I think i'm not adding the actual object itself to the copy list away, but rather I'm adding the name attribute only. Also, it is lagging on the iPhone. Any advice?
Edit:
Or is there a way to link this up with NSFetchedResultsController and go that route?
You need to add an NSPredicate to your NSFetchRequest.
精彩评论