twitter-text-objc — An Objective-C implementation of Twitter's text processing library

Twitter released a version of their twitter-text library for Objective-C today. It makes extracting entities from strings really easy.

Here’s the header:

+ (NSArray*)extractEntities:(NSString*)text;
+ (NSArray*)extractURLs:(NSString*)text;
+ (NSArray*)extractHashtags:(NSString*)text checkingURLOverlap:(BOOL)checkingURLOverlap;
+ (NSArray*)extractMentionedScreenNames:(NSString*)text;
+ (NSArray*)extractMentionsOrLists:(NSString*)text;
+ (TwitterTextEntity*)extractReplyScreenName:(NSString*)text;
+ (int)tweetLength:(NSString*)text;

Extracting the URLs from a string is super simple:

NSArray *URLs = [TwitterText extractURLs:@"4 new HTTP status codes http://tools.ietf.org/html/rfc6585"];
TwitterTextEntity *entity = [URLs objectAtIndex:0];
NSLog(@"Entity range: %@", NSStringFromNSRange(entity.range));
// Entity range: {24, 34}

The source is on GitHub. There’s a Ruby, JavaScript, and Java version of this library as well.

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

 
0:00 / 0:00