Skip to content

Instantly share code, notes, and snippets.

@keldelice
Forked from vickeryj/gist:66593
Created February 19, 2009 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keldelice/66789 to your computer and use it in GitHub Desktop.
Save keldelice/66789 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