Guest User

Untitled

a guest
Oct 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. NSDictionary *tweet = [self.tweets objectAtIndex:indexPath.row];
  2. NSString *text = [tweet objectForKey:@"text"];
  3. NSError *error;
  4. NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:@"\\bhttps?://[a-zA-Z0-9\\-.]+(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?" options:0 error:&error];
  5.  
  6. __block NSUInteger count = 0;
  7. __block NSMutableSet *links = [[NSMutableSet alloc] initWithCapacity:100];
  8. [reg enumerateMatchesInString:text
  9. options:0
  10. range:NSMakeRange(0, [text length])
  11. usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
  12. [links addObject:[text substringWithRange:result.range]];
  13. if ( ++count >= 100 ) {
  14. *stop = YES;
  15. }
  16. }];
  17.  
  18. NSMutableArray *items = [NSMutableArray new];
  19. [items addObject:[NSString stringWithFormat:@"%@'s Twitter Stream",[tweet objectForKey:@"from_user"]]];
  20. for (NSString *string in links) {
  21. [items addObject:string];
  22. }
Add Comment
Please, Sign In to add comment