Skip to content

Instantly share code, notes, and snippets.

@toranb
Created October 27, 2011 23:23
Show Gist options
  • Select an option

  • Save toranb/1321184 to your computer and use it in GitHub Desktop.

Select an option

Save toranb/1321184 to your computer and use it in GitHub Desktop.
Code that was not test driven
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
if (responseString == @"") {
[viewController callBackWithMovieDescription:@"failed to load details"];
}else{
NSString* desc = @"";
NSRange textRange =[[responseString lowercaseString] rangeOfString:[@"<div class=\"inforow desc\">" lowercaseString]];
NSRange finalRange;
NSRange endRange;
NSRange range;
if(textRange.location != NSNotFound)
{
int startAt = textRange.location;
range = NSMakeRange(startAt, 900);
desc = [responseString substringWithRange: range];
endRange = [[desc lowercaseString] rangeOfString:[@"</div>" lowercaseString]];
if(endRange.location != NSNotFound)
{
finalRange = NSMakeRange((startAt+107), (endRange.location-107));
desc = [responseString substringWithRange: finalRange];
}else{
range = NSMakeRange(startAt, 1200);
desc = [responseString substringWithRange: range];
endRange = [[desc lowercaseString] rangeOfString:[@"</div>" lowercaseString]];
if(endRange.location != NSNotFound)
{
finalRange = NSMakeRange((startAt+107), (endRange.location-107));
desc = [responseString substringWithRange: finalRange];
}else{
range = NSMakeRange(startAt, 1500);
desc = [responseString substringWithRange: range];
endRange = [[desc lowercaseString] rangeOfString:[@"</div>" lowercaseString]];
if(endRange.location != NSNotFound)
{
finalRange = NSMakeRange((startAt+107), (endRange.location-107));
desc = [responseString substringWithRange: finalRange];
}else{
desc = @"failed to load details";
}
}
}
}else{
desc = @"failed to load details";
}
[viewController callBackWithMovieDescription:desc];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment