From 450ff56e54b24f18fc0662ad5f3d5db00756b4ee Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 22 Aug 2011 10:44:16 -0500 Subject: [PATCH] Fixing example in README to use user-defined NSOperationQueue Reorganizing examples --- README.md | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a915bdf..e12fb7f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http AFJSONRequestOperation *operation = [AFJSONRequestOperation operationWithRequest:request success:^(id JSON) { NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"], [JSON valueForKeyPath:@"last_name"]); }]; -[[NSOperationQueue mainQueue] addOperation:operation]; + +NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; +[queue addOperation:operation]; ``` ### Image Request @@ -29,6 +31,16 @@ UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0 [imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]]; ``` +### REST API Client Request + +``` objective-c +// AFGowallaAPIClient is a subclass of AFRestClient, which defines the base URL and default HTTP headers for NSURLRequests it creates +[[AFGowallaAPIClient sharedClient] getPath:@"/spots/9223" parameters:nil success:^(id response) { + NSLog(@"Name: %@", [response valueForKeyPath:@"name"]); + NSLog(@"Address: %@", [response valueForKeyPath:@"address.street_address"]); +}]; +``` + ### File Upload with Progress Callback ``` objective-c @@ -43,7 +55,9 @@ AFHTTPRequestOperation *operation = [AFHTTPRequestOperation operationWithRequest [operation setProgressBlock:^(NSUInteger totalBytesWritten, NSUInteger totalBytesExpectedToWrite) { NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite); }]; -[[NSOperationQueue mainQueue] addOperation:operation]; + +NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; +[queue addOperation:operation]; ``` ### Request With HTTP Authorization Header @@ -64,17 +78,8 @@ AFHTTPRequestOperation *operation = [AFHTTPRequestOperation operationWithRequest } }]; -[[NSOperationQueue mainQueue] addOperation:operation]; -``` - -### REST API Client Request - -``` objective-c -// AFGowallaAPIClient is a subclass of AFRestClient, which defines the base URL and default HTTP headers for NSURLRequests it creates -[[AFGowallaAPIClient sharedClient] getPath:@"/spots/9223" parameters:nil success:^(id response) { - NSLog(@"Name: %@", [response valueForKeyPath:@"name"]); - NSLog(@"Address: %@", [response valueForKeyPath:@"address.street_address"]); -}]; +NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; +[queue addOperation:operation]; ``` ### Streaming Request