completionhandler

Nested closures does not like argument list

喜夏-厌秋 提交于 2019-11-30 08:16:18
问题 A UIView needs to change a warning label depending on the completion handler of a custom control: voucherInputView.completionHandler = {[weak self] (success: Bool) -> Void in self?.proceedButton.enabled = success self?.warningLabel.alpha = 1.0 if success { self?.warningLabel.text = "Code you entered is correct" self?.warningLabel.backgroundColor = UIColor.greenColor() } else { self?.warningLabel.text = "Code you entered is incorrect" self?.warningLabel.backgroundColor = UIColor.orangeColor()

Swift 3 :Closure use of non-escaping parameter may allow it to escape

扶醉桌前 提交于 2019-11-30 07:11:03
问题 I have the following function where I have completion handler but I'm getting this error: Closure use of non-escaping parameter may allow it to escape Here is my code: func makeRequestcompletion(completion:(_ response:Data, _ error:NSError)->Void) { let urlString = URL(string: "http://someUrl.com") if let url = urlString { let task = URLSession.shared.dataTask(with: url, completionHandler: { (data, urlRequestResponse, error) in completion(data, error) // <-- here is I'm getting the error })

Completion handler is not called on iOS7 GM

ε祈祈猫儿з 提交于 2019-11-30 06:47:05
I'm using AVAssetWriter, and it is perfectly working on iOS6. The problem is, when I called finishWritingWithCompletionHandler , the completion handler is not called on iOS7 GM. I called markAsFinished , and even endSessionAtSourceTime before I call finishWritingWithCompletionHandler. It works fine on iOS6. And even more, on iOS7, it works some times, and then it doesn't work again. I don't know why, but it works if I call the method using alert view. So I tried performSelectorOnMainThread and inBackground , but it didn't help. Any ideas? Apparently you need to retain the assetWriter now. You

How does a completion handler work on iOS?

懵懂的女人 提交于 2019-11-29 22:26:11
Im trying to understand completion handlers & blocks. I believe you can use blocks for many deep programming things without completion handlers, but I think i understand that completion handlers are based on blocks. (So basically completion handlers need blocks but not the other way around). So I saw this code on the internet about the old twitter framework: [twitterFeed performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { if (!error) { self.successLabel.text = @"Tweeted Successfully"; [self playTweetSound]; } else { // Show alert } // Stop

How to read a request using CompletionHandlers and a ByteBuffer smaller than the request?

≡放荡痞女 提交于 2019-11-29 21:11:26
问题 I am using Java 7 and AsynchronousSocketChannel. I would like to read a request (e.g. HTTP POST ) but I'm struggling to come up with a nice solution to read the full request, if it's bigger than the size of the ByteBuffer I'm using. E.g. if the ByteBuffer is 4048 bytes and the HTTP POST contains an image that is larger than 4kB. Is there any nice recursive solution or loop for this? Here is my code for reading requests: public void readRequest(final AsynchronousSocketChannel ch) { final

Set address string with reverseGeocodeLocation: and return from method

陌路散爱 提交于 2019-11-29 08:52:31
I'm try to localize a start and end point to an address string, so that I can store it into NSUserDefaults . The problem is that the method continues executing and does not set my variable. NSLog(@"Begin"); __block NSString *returnAddress = @""; [self.geoCoder reverseGeocodeLocation:self.locManager.location completionHandler:^(NSArray *placemarks, NSError *error) { if(error){ NSLog(@"%@", [error localizedDescription]); } CLPlacemark *placemark = [placemarks lastObject]; startAddressString = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@", placemark.subThoroughfare, placemark.thoroughfare,

UIActivityViewController completionHandler how to check if activity send or not successfully?

和自甴很熟 提交于 2019-11-29 08:45:14
I want to send one string via airdrop, I want to call one function when the String is received on other device successfully. I had implemented it through UIActivityViewController and I check it via completionHandler. Here is my scenario : Device A ->send a string To Device B If Device B receive have two option -> Accept or Decline I want to call one function on Device A when Device B will receive or Decline that message. Below is my implementation: UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[self.customURLContainer]

Nested closures does not like argument list

风格不统一 提交于 2019-11-29 06:20:49
A UIView needs to change a warning label depending on the completion handler of a custom control: voucherInputView.completionHandler = {[weak self] (success: Bool) -> Void in self?.proceedButton.enabled = success self?.warningLabel.alpha = 1.0 if success { self?.warningLabel.text = "Code you entered is correct" self?.warningLabel.backgroundColor = UIColor.greenColor() } else { self?.warningLabel.text = "Code you entered is incorrect" self?.warningLabel.backgroundColor = UIColor.orangeColor() } UIView.animateWithDuration(NSTimeInterval(1.0), animations:{ ()-> Void in self?.warningLabel.alpha =

Swift 3 :Closure use of non-escaping parameter may allow it to escape

ⅰ亾dé卋堺 提交于 2019-11-29 02:07:14
I have the following function where I have completion handler but I'm getting this error: Closure use of non-escaping parameter may allow it to escape Here is my code: func makeRequestcompletion(completion:(_ response:Data, _ error:NSError)->Void) { let urlString = URL(string: "http://someUrl.com") if let url = urlString { let task = URLSession.shared.dataTask(with: url, completionHandler: { (data, urlRequestResponse, error) in completion(data, error) // <-- here is I'm getting the error }) task.resume() } } Any of you knows why I'm getting this error? I'll really appreciate you help Looks

Difference Between Completion Handler and Blocks : [iOS]

 ̄綄美尐妖づ 提交于 2019-11-28 07:27:35
I am messed with both completion handler and blocks while I am using them in Swift and Objective-C . And when I am searching blocks in Swift on google it is showing result for completion handler! Can somebody tell me what is the difference between completion handler and blocks with respect to Swift and Objective-C ? Here you can easily differentiate between blocks and completion handlers in fact both are blocks see detail below. Blocks: Blocks are a language-level feature added to C, Objective-C and C++, which allow you to create distinct segments of code that can be passed around to methods