Skip to content

Instantly share code, notes, and snippets.

@aaronpearce
Created October 26, 2011 08:55
Show Gist options
  • Save aaronpearce/1315823 to your computer and use it in GitHub Desktop.
Save aaronpearce/1315823 to your computer and use it in GitHub Desktop.
La
-(void)getDeviationsFromFolder:(int)folderID fromStart:(int)start ToOffset:(int)offset {
// Casting int to string
NSString *theFolderID = [NSString stringWithFormat:@"%d", folderID];
NSString *theStart = [NSString stringWithFormat:@"%d", start];
NSString *theOffset = [NSString stringWithFormat:@"%d", offset];
NSString *theURL = deviationWatch;
// Swapping out ints to string
theURL = [[[theURL stringByReplacingOccurrencesOfString:@"folderid" withString:theFolderID] stringByReplacingOccurrencesOfString:@"start" withString:theStart] stringByReplacingOccurrencesOfString:@"offset" withString:theOffset];
NSURL *url = [NSURL URLWithString:theURL];
// Grab result
// Sets to allow into the block
__block APAppDelegate *appDele = (APAppDelegate *)[[UIApplication sharedApplication] delegate];
__block APMasterViewController *amvc = [appDele.navigationController topViewController];
id result = [appDele DiFiRequestWithURL:url];
// Runs a loop on the result looping through the responses
[[result valueForKey:@"response"] enumerateObjectsUsingBlock:^(id response, NSUInteger idx, BOOL *stop) {
// Checks if count is not 0?
if([[response valueForKeyPath:@"content.result.count"] objectAtIndex:0] != 0) {
// Loops through the hits from the query
[[[response valueForKeyPath:@"content.result.hits"] objectAtIndex:0] enumerateObjectsUsingBlock:^(id hit, NSUInteger idx, BOOL *stop) {
// Checks if there are hits
if([hit count] != 0) {
// add to the dataSet to be shown
[amvc.dataSet addObject:hit];
}
}];
}
// if stop is true, reload the table
if(stop)
[amvc.tableView reloadData];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment