Skip to content

Instantly share code, notes, and snippets.

@bryanjclark
Created January 12, 2014 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanjclark/8391889 to your computer and use it in GitHub Desktop.
Save bryanjclark/8391889 to your computer and use it in GitHub Desktop.
Here's how I grab the matching #topics in Threadnote, based on the substring of text that's been typed so far.
-(void)showTagTableWithString:(NSString *)partialTagString {
[self.noteTextView setSpellCheckingType:UITextSpellCheckingTypeNo];
//If there isn't any string
if (partialTagString.length == 0) {
//Display all of the tags, sorted by most recently used.
NSFetchRequest *hashtagRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *tagEntityDescription = [NSEntityDescription entityForName:@"Tags"
inManagedObjectContext:self.note.managedObjectContext];
[hashtagRequest setEntity:tagEntityDescription];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dateLastUsed"
ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[hashtagRequest setSortDescriptors:sortDescriptors];
tagsToDisplay = (NSMutableArray *)[self.note.managedObjectContext executeFetchRequest:hashtagRequest error:nil];
if ([tagsToDisplay count] >0)
{
[self showTagTable];
[tagListTable reloadData];
}
} else {
//Display all of the tags that match the partial tag string
NSFetchRequest *hashtagRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *tagEntityDescription = [NSEntityDescription entityForName:@"Tags"
inManagedObjectContext:self.note.managedObjectContext];
[hashtagRequest setEntity:tagEntityDescription];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dateLastUsed"
ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[hashtagRequest setSortDescriptors:sortDescriptors];
NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", partialTagString];
[hashtagRequest setPredicate:tagPredicate];
tagsToDisplay = (NSMutableArray *)[self.note.managedObjectContext executeFetchRequest:hashtagRequest error:nil];
[self showTagTable];
[tagListTable reloadData];
//If there are no matching hashtags, then let's hide the tag table.
if ([tagsToDisplay count] == 0)
{
[self hideTagTable];
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment