Skip to content

Instantly share code, notes, and snippets.

@mysteriouspants
Created September 28, 2012 21:13
Show Gist options
  • Save mysteriouspants/3802099 to your computer and use it in GitHub Desktop.
Save mysteriouspants/3802099 to your computer and use it in GitHub Desktop.
FSURLOperation Example
NSURLRequest* req= [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://fsdev.net"]];
__block NSData* mySite= nil;
FSURLOperation* oper= [FSURLOperation URLOperationWithRequest:req completionBlock:^(NSHTTPURLResponse* resp, NSData* payload, NSError* asplosion) {
mySite = payload;
}];
NSBlockOperation* onFinish= [NSBlockOperation blockOperationWithBlock:^{
NSMutableURLRequest* spamReq= [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.fsdev.net/"]];
[spamReq setHTTPBody:mySite];
FSURLOperation* spamOper= [FSURLOperation URLOperationWithRequest:req completionBlock:^(NSHTTPResponse* resp, NSData* payload, NSError* asplosion) {
NSLog(@"%@", [payload fs_stringValue]);
}];
[[NSOperationQueue mainQueue] addOperation:spamOper];
}];
[onFinish addDependency:oper];
[[NSOperationQueue mainQueue] addOperations:[NSArray arrayWithObjects:onFinish, oper, nil]
waitUntilDone:NO];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment