Created
January 12, 2014 23:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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