ios - How to create block with patameters? ios7 -
Let me create a block like this:
1) Define your own completed block ,
typingfile (^ myCompletion) (BOOL);
2) Create a method that takes your entire block as a complete parameter,
- (zero) myMethod: (myCompletion) compblock {// do stuff compblock (yes); }
3) How do you use it,
[my mymethod: ^ (BOOL end) {if (end) {NSLog (@ " Success"); }}];
How can I send the array to the block and then how can I get a new array from the block?
// Here I got an array of image IDs and go to the loop to download it, NSString * URLString = [NSString stringWithFormat: @ "% @", request string ]; NSURL * url = [NSURL URLWithString: URLString]; NSURLRequest * urlRequest = [NSURL request request with url: url]; AFHTTPRequestOperation * Request Operation = [[PHPTraffic Operation Allocon] InitVatRezeStrite: URLReverest]; RequestOperation.responseSerializer = [AFImageResponseSerializer serializer]; [Request Operation Setup Block Volume Successful: ^ (FHttpKAEASTA Operation * Operation, ID Reaction Object) {userWithImage = [responseObject copy]; } Failure: ^ (FHTPPKAESTA Operation * Operation, NSERR * Error) {NSLog (@ "Image Error:% @", Error); }]; [Request Started Operation]; // Here I save it to the temporary array and send it as a complete block,
Yes, I think it would be better to send 1 image ID and return it to block 1 image. And in the method I will call the block - I will take different actions from the picture. So, is it possible to do this? I can do anything with NSNotification, but it can be more widely when it is in blocks.
If you just want to write a cover around AirSenputing
request, then you can write a method like this:
- (zero) downloadImageWithPath: (NSString *) path Completion: (Zero (^) (FHTPPKAEASTE Operation * Operation, UIM image * image, NSEROM * error) Completion __trat__ ((non-blue) (2))); {NSParameterAssert}; NSURL * url = [NSURL URLWithString: Path]; NSURLRequest * urlRequest = [NSURL request request with url: url]; AFHTTPRequestOperation * Request Operation = [[PHPTraffic Operation Allocon] InitVatRezeStrite: URLReverest]; RequestOperation.responseSerializer = [AFImageResponseSerializer serializer]; [Request Operation Setup Blockwidth Successful: ^ (FHttpQuest Operation * Operation, ID Reaction Object) {Closing (Operation, Response object, Zero); } Failure: ^ (FHTPPKAEASTA Operation * Operation, NSERR * Error) {Closing (Operations, Zero, Error); }]; [Request Started Operation]; }
You will call it with something like this:
[self downloadimageWithPath: @ "http: //url/to/image.jpg" Closing: ^ (FHTPPKAEAST Operation * Operation, UIImage * Image, NSERR * Error) {if (Error) {// Handle Error Return; } Dispatch_async (dispatch_get_main_queue (), ^ {// update UI with Image}); }];
Comments
Post a Comment