This file contains 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
- (NSString *)stripOutHttp:(NSString *)httpLine { | |
// Setup an NSError object to catch any failures | |
NSError *error = NULL; | |
// create the NSRegularExpression object and initialize it with a pattern | |
// the pattern will match any http or https url, with option case insensitive | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?" options:NSRegularExpressionCaseInsensitive error:&error]; | |
// create an NSRange object using our regex object for the first match in the string httpline | |
NSRange rangeOfFirstMatch = [regex rangeOfFirstMatchInString:httpLine options:0 range:NSMakeRange(0, [httpLine length])]; | |
// check that our NSRange object is not equal to range of NSNotFound | |
if (!NSEqualRanges(rangeOfFirstMatch, NSMakeRange(NSNotFound, 0))) { |
This file contains 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
- (NSString *)grabData:(NSString *)searchTerm { | |
// Setup an error to catch stuff in | |
NSError *error = NULL; | |
//Create the regular expression to match against | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\s" options:NSRegularExpressionCaseInsensitive error:&error]; | |
// create the new string by replacing the matching of the regex pattern with the template pattern(whitespace) | |
NSString *newSearchString = [regex stringByReplacingMatchesInString:searchTerm options:0 range:NSMakeRange(0, [searchTerm length]) withTemplate:@"%20"]; | |
NSLog(@"New string: %@",newSearchString); | |
return newSearchString; | |
} |
This file contains 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)touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event { | |
for (UIView* view in self.view.subviews) { | |
if ([view isKindOfClass:[UITextField class]]) | |
[view resignFirstResponder]; | |
} | |
} |
This file contains 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)initialize | |
{ | |
//configure iRate | |
[iRate sharedInstance].appStoreID = 355313284; | |
} |
This file contains 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
#import <Foundation/Foundation.h> | |
@interface SearchTwitter : NSObject { | |
NSMutableData *tweetBlob; | |
} | |
- (void)grabData:(NSString *)searchTerm; | |
@end |
This file contains 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
//Create the regular expression to match against whitespace or % or ^ | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\s|%|^)" options:NSRegularExpressionCaseInsensitive error:&error]; | |
//Create the regular expression to match against hash tags | |
NSRegularExpression *regexHash = [NSRegularExpression regularExpressionWithPattern:@"#" options:NSRegularExpressionCaseInsensitive error:&error]; | |
// create the new string by replacing the matching of the regex pattern with the template pattern(whitespace) | |
NSString *tempString = [regex stringByReplacingMatchesInString:searchTerm options:0 range:NSMakeRange(0, [searchTerm length]) withTemplate:@"%20"]; | |
// create the new string by replacing the matching of the regex pattern with the template pattern(whitespace) |
This file contains 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
// Build the string to search against the twitter search api | |
NSString *urlString = [NSString stringWithFormat:@"http://search.twitter.com/search.json?q=&ands=%@&phrase=&rpp=50",searchTerm]; | |
NSURL *url = [NSURL URLWithString:urlString]; |
This file contains 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
//Setup and start async download | |
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; | |
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; | |
[connection release]; | |
[request release]; |
This file contains 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
// Gather up all the asynch data as it comes in and store it in the blob | |
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { | |
// Check to see if this is a new search, if so it will be nil, so create an object | |
if(tweetBlob == nil) { | |
tweetBlob = [[NSMutableData alloc]init]; | |
[tweetBlob appendData:data]; | |
} | |
else { | |
[tweetBlob appendData:data]; |
This file contains 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
// Once the data is complete, then we can parse it | |
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { | |
// Store data blob we got back from twitter into a JSON string | |
NSString *jsonString = [[NSString alloc] initWithData:tweetBlob encoding:NSUTF8StringEncoding]; | |
//Now use the Create a dictionary from the JSON string | |
NSDictionary *results = [jsonString JSONValue]; | |
// Build an Array from the dictionary for easy access to each entry |
OlderNewer