Created
September 28, 2012 21:13
-
-
Save mysteriouspants/3802099 to your computer and use it in GitHub Desktop.
FSURLOperation Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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