I have just started IPhone programming. I am trying to develop a dictionary application where by someone types a word and the word is transfered to a dictionary web site and it sends back the word definition back to the phone. Have found some code that seams to do this. Has anyone solved this problem and have they any tips.
(void)getNewValuesFromDB{
NSString *web = @"http://www.urbandictionary.com/iphone/search/random";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:web]];
NSURLResponse *response = nil;
NSError *err = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &err];
NSString *text = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
if (text != nil)
{
NSString *beginWordDefinition = @"<div class='word'>";
NSString *beginDefinition = @"<div class='word'>";
NSString *endDefinition = @"</div>";
NSRange star;
NSRange searchRange = NSMakeRange(star.location, [responseData length] - star.length);
star = [text rangeOfString:beginDefinition];
if (star.length > 1)
{
NSLog(@"star lenght is %i", star.length);
NSLog(@"star location is %i", star.location);
NSRange searchRange = NSMakeRange(star.location + star.length, 20000);
NSLog(@"searchRange lenght is %i", searchRange.length);
NSLog(@"searchRange location is %i", searchRange.location);
text = NSStringFromRange(searchRange);
NSLog(@"text is %@", text);
star = [text rangeOfString:endDefinition];
NSLog(@"star lenght is %i", star.length);
NSLog(@"star location is %i", star.location);
word = NSStringFromRange(star);
NSLog(@"word is %@", word);
NSLog(@"star location is %S", star);
}
}
(void)getNewValuesFromDB{
NSString *web = @"http://www.urbandictionary.com/iphone/search/random";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:web]];
NSURLResponse *response = nil;
NSError *err = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &err];
NSString *text = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
if (text != nil)
{
NSString *beginWordDefinition = @"<div class='word'>";
NSString *beginDefinition = @"<div class='word'>";
NSString *endDefinition = @"</div>";
NSRange star;
NSRange searchRange = NSMakeRange(star.location, [responseData length] - star.length);
star = [text rangeOfString:beginDefinition];
if (star.length > 1)
{
NSLog(@"star lenght is %i", star.length);
NSLog(@"star location is %i", star.location);
NSRange searchRange = NSMakeRange(star.location + star.length, 20000);
NSLog(@"searchRange lenght is %i", searchRange.length);
NSLog(@"searchRange location is %i", searchRange.location);
text = NSStringFromRange(searchRange);
NSLog(@"text is %@", text);
star = [text rangeOfString:endDefinition];
NSLog(@"star lenght is %i", star.length);
NSLog(@"star location is %i", star.location);
word = NSStringFromRange(star);
NSLog(@"word is %@", word);
NSLog(@"star location is %S", star);
}
}