completion-block

Return object for a method inside completion block

夙愿已清 提交于 2019-12-23 02:34:45
问题 I want to make a method with URL parameter that returns the response of calling that URL. How can I return the data obtained inside a completion block for a method? class func MakeGetRequest(urlString: String) -> (data: NSData, error: NSError) { let url = NSURL(string: urlString) var dataResponse: NSData var err: NSError let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in //How can I return the data obtained here.... }) task

Using Obj-C completion block in Swift

元气小坏坏 提交于 2019-12-10 18:15:31
问题 In Objective-C, I have a completion block class defined as: File.h typedef void (^MYCompletionBlock)(BOOL success, NSDictionary *result, NSError *error); Then, in a Swift file, I try to use the completion block as follows: Swift.swift class MyClass: NSObject{ ... func MyFunction() -> Void { ... objcMethod(param1, withCompletion: {(MYCompletionBlock) -> Void in if (success){ // Error:"Use of unresolved identifier 'success'" } } ... } ... } But, I keep getting an error: "Use of unresolved

How to have a completion handler/block after Alamofire Post request?

眉间皱痕 提交于 2019-12-10 15:19:48
问题 I have a method which handles a Apple Push Notification Service remote notification. When this method is executed, I want it to call my server and do a HTTP POST request using the Alamofire library. I want to execute another method that will handle the response of the POST request. The problem for me is that I am using an existing API to fetch a profile from the server in this POST request. So I need to use this existing API and figure out when this profile fetch is specifically triggered

Swift Async With Completion Block

浪子不回头ぞ 提交于 2019-12-03 22:32:57
问题 I have two functions that executes async. I tried to "syncronize" them with: DispatchGroup and DispatchQueue let queue = DispatchQueue(label: "com.company.app.queue", attributes: .concurrent) let group = DispatchGroup() queue.async(group: group) { //func1 } queue.async(group: group) { //func2 } group.notify(queue: queue) { print("#3 finished") } Func1 and Func2 are only calls of: class func getDataFromUrl( url: URL, completion: @escaping ( Data?, URLResponse?, Error? ) -> ( ) ) { URLSession

Swift Async With Completion Block

China☆狼群 提交于 2019-12-01 01:20:43
I have two functions that executes async. I tried to "syncronize" them with: DispatchGroup and DispatchQueue let queue = DispatchQueue(label: "com.company.app.queue", attributes: .concurrent) let group = DispatchGroup() queue.async(group: group) { //func1 } queue.async(group: group) { //func2 } group.notify(queue: queue) { print("#3 finished") } Func1 and Func2 are only calls of: class func getDataFromUrl( url: URL, completion: @escaping ( Data?, URLResponse?, Error? ) -> ( ) ) { URLSession.shared.dataTask( with: url ) { data, response, error in completion( data, response, error ) }.resume( )

Stop an auto-reverse / infinite-repeat UIView animation with a BOOL / completion block

你。 提交于 2019-11-30 11:10:56
I'm setting up the following UIView animateWithDuration: method, with the intention of setting my animationOn BOOL elsewhere in the program to cancel that infinite looped repeat. I was under the impression that the completion block would be called each time a cycle of the animation ends, but this doesn't appear to be the case. Is the completion block ever called in a repeating animation? And if not, is there another way I can stop this animation from outside this method? - (void) animateFirst: (UIButton *) button { button.transform = CGAffineTransformMakeScale(1.1, 1.1); [UIView

User interaction with uiview and animation completion blocks

帅比萌擦擦* 提交于 2019-11-30 04:56:38
问题 I have the following code: [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ imageView.bounds = endBounds; } completion:^(BOOL finished) { [UIView animateWithDuration:2.0 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction animations:^{ imageView.bounds = startBounds; } completion:^(BOOL finished) { [imageView removeFromSuperview]; }]; }]; Additionally I have: [imageView setUserInteractionEnabled:YES]; and a tap gesture

Stop an auto-reverse / infinite-repeat UIView animation with a BOOL / completion block

☆樱花仙子☆ 提交于 2019-11-29 16:15:00
问题 I'm setting up the following UIView animateWithDuration: method, with the intention of setting my animationOn BOOL elsewhere in the program to cancel that infinite looped repeat. I was under the impression that the completion block would be called each time a cycle of the animation ends, but this doesn't appear to be the case. Is the completion block ever called in a repeating animation? And if not, is there another way I can stop this animation from outside this method? - (void) animateFirst