completionhandler

wait for two asynchronous completion functions to finish, before executing next line code

对着背影说爱祢 提交于 2021-02-18 03:40:50
问题 I have two functions: func Females_NonChat() and func males_NonChat() I want to wait for both of them to finish before executing the print statement in viewdidload. Do I need another completion handler to accomplish that? Those functions used are firebase completion handlers for requesting information from the online database... override func viewDidLoad() { super.viewDidLoad() func Females_NonChat() func males_NonChat() print("finished executing both asynchronous functions") } func Females

completion handler to finish tasks before running another

半世苍凉 提交于 2021-01-29 07:46:44
问题 I'm really tying myself up in a knot here getting very confused with how to perform tasks in the order i want them to happen. i have function to build an array from server data and return a result which is the array. - this works fine and does return the result. upon the completion of this happening (twice) i want to run another function. for some reason at the moment i am trying to embed these functions in another function with a completion block that will return true once these 2 have

Handle completion if no success when opening url with SafariViewController

空扰寡人 提交于 2020-08-09 13:59:42
问题 Is there a way to handle the case if SafariViewController fails to open a url like you can with UIApplication.shared.open ? This is my function: if ["http", "https"].contains(url.scheme?.lowercased() ?? "") { // Can open with SFSafariViewController let safariViewController = SFSafariViewController(url: url) self.present(safariViewController, animated: true) { // no bool given? } } else { // Scheme is not supported or no scheme is given, use openURL guard let url = URL(string: urlString) else

Handle completion if no success when opening url with SafariViewController

情到浓时终转凉″ 提交于 2020-08-09 13:59:07
问题 Is there a way to handle the case if SafariViewController fails to open a url like you can with UIApplication.shared.open ? This is my function: if ["http", "https"].contains(url.scheme?.lowercased() ?? "") { // Can open with SFSafariViewController let safariViewController = SFSafariViewController(url: url) self.present(safariViewController, animated: true) { // no bool given? } } else { // Scheme is not supported or no scheme is given, use openURL guard let url = URL(string: urlString) else

Swift completion handler with Firebase

落爺英雄遲暮 提交于 2020-06-11 07:46:27
问题 I am trying to get a list of 'players' from Firebase from the child node 'PlayerInPool' by calling the following functions func getPlayersInPool(completion: @escaping (_ success: Bool) -> Void) { self.handle = self.poolPlayersRef.child(self.pID)observe(.value, with: { snapshot in // Calling the second function self.loadPlayersInPool(/*items: items,*/ snapshot: snapshot) { (success) -> Void in if success { print("Players Array Count = ", self.players.count) for j in 0 ..< self.players.count {

How to call function after async requests finish in SwiftUI?

倖福魔咒の 提交于 2020-05-16 08:59:40
问题 I have a function that calls 2 types of api requests to get a bunch of data i need in my app. In the function I make a request for locations, then for each location in the response I make a different request to get details of that specific location. (ex. if request 1 returns 20 locations, my second request is called 20 times, once for each location) My function code here: func requestAndCombineGData(location: CLLocation, radius: Int) { // Clears map of markers self.mapView.clear() // Calls

How to get data to return from NSURLSessionDataTask in Swift

久未见 提交于 2020-01-14 04:08:14
问题 I have this same question as was asked and answered here: How to get data to return from NSURLSessionDataTask The difference: How can I do this in Swift? I do not know Objective C at all so trying to interpret that answer is proving a bit futile for me.. So given the code below I have a FirstViewController which will call my HomeModel class to go and get the data using a NSURLSession call. Once the call is complete I want return the data to the FirstViewController so that I may go and set it

Completion handlers in Java?

六月ゝ 毕业季﹏ 提交于 2020-01-12 04:42:33
问题 I've been coding for iOS and I'm quite familiar with the concept of blocks in Objective-C. Now I'm leaning Java for Android and trying to convert some apps from Android to iOS. I read that there no perfect equivalent of blocks in Java, so I'd like to know what is the best alternative to implement completion handlers or anything that could work similarly. 回答1: Interface types, in general. You can use Runnable (which is an interface ) as Rob suggested if your handler has no parameters and a