Skip to content

Instantly share code, notes, and snippets.

@vickeryj
Created February 18, 2009 22:33
Show Gist options
  • Save vickeryj/66593 to your computer and use it in GitHub Desktop.
Save vickeryj/66593 to your computer and use it in GitHub Desktop.
@implementation MyAppDelegate
static NSOperationQueue *sharedOperationQueue = nil;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//setup the operation queue
sharedOperationQueue = [[NSOperationQueue alloc] init];
//limit the number of concurrent operations to 1, as performance suffers on the iPhone otherwise
[sharedOperationQueue setMaxConcurrentOperationCount:1];
//Configure ObjectiveResource
[ObjectiveResourceConfig setSite:@"http://localhost:3000/"];
// use json
[ObjectiveResourceConfig setResponseType:JSONResponse];
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
// put job in operation queue and run it when able
+ (void) runJob:(SEL)selector onTarget:(id)target withArgument:(id)argument {
NSInvocationOperation *operation = [[[NSInvocationOperation alloc] initWithTarget:target
selector:selector
object:argument] autorelease];
[sharedOperationQueue addOperation:operation];
}
@end
@implementation MyViewController
- (void) loadPeople {
self.people = [Person findAllRemote];
[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}
-(IBAction) refreshButtonWasPressed {
//when the refresh button is pressed, call loadPeople as a new operation
[MyAppDelegate runJob:@selector(loadPeople) onTarget:self withArgument:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment