Hi I am using this library and I found the function:
- (void) queueRequest:(NSString*)urlPath completion:(void(^)(NSData*))completionWithDownloadedData;
I try to pass a simple NSData *data;
and it throw an error, what really mean (void(^)(NSData*))
? Is the first time that I see it.
Thanks a lot.
(void(^)(NSData*))
declares a code block.
You can call your function this way.
[obj queueRequest:urlPath completion:^(NSData* data){
/* some code */
}];
data
is a parameter to your block, which you can work with. The block will be called when the queueRequest will finish, asynchronously.
The interface is asynchronous, meaning that the data will only be available sometime later. This means that the method can’t simply return the NSData*
(without blocking for all the time, which is impractical). The problem is nowadays often solved with blocks, and the completion argument here is a block that takes an NSData*
argument and returns void
. This is how you call such a method:
[foo queueRequest:path completion:^(NSData *receivedData) {
NSLog(@"Received data: %@", receivedData);
}];
The call will return immediately and the block will be executed sometime later, when the data is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With