completionhandler

How To Check If An Email Address Is Already In Use Firebase

你离开我真会死。 提交于 2019-12-09 07:04:52
问题 working on some FirAuth things, but for some reason I can't figure out how to check if the users proposed email address has already been taken. I've tried calling .fetchProvidersForEmail as suggested in other questions from a while back, but for whatever reason it just won't work. Also, I'm very green when it comes to completion handlers, so any constructive criticism on that would be welcome as well. So, for now, the parts of my code that pertain to this are: import UIKit import Firebase

Objective C How to return outer function from inside async inner function

天涯浪子 提交于 2019-12-08 12:35:50
问题 I want to return from outer function from inside async inner function. In swift, I would have used completion handler for this purpose which would escape from function. But in objective c, completion handler won't actually return from function: My function looks like this: -(void)chosenFrom:(NSDictionary<NSString *,id> *)info{ [self asyncCode:info withCompletion:^(NSData *imageData) { if(imageData) { // I want to return from chosenFrom function ***inside here.*** } }]; // This is to

Using a value from Alamofire request outside the function

风流意气都作罢 提交于 2019-12-08 02:47:45
问题 I can't seem to figure this one out: I am trying to get an error from my server (in JSON) using an Alamofire request, but I cannot get the value outside the function. This is the implementation of my function: func alamoRequest(username : String, email: String, password: String, facebook: String, completionHandler : (String?) -> Void) { var jsonValue : JSON? let URL = "http://someurl.com/login.php" let requestParameters = ["username" : username, "email" : email, "password" : password,

What makes a completion handler execute the block when your task of interest is complete?

自古美人都是妖i 提交于 2019-12-07 15:42:51
问题 I have been asking and trying to understand how completion handlers work. Ive used quite a few and I've read many tutorials. i will post the one I use here, but I want to be able to create my own without using someone else's code as a reference. I understand this completion handler where this caller method: -(void)viewDidLoad{ [newSimpleCounter countToTenThousandAndReturnCompletionBLock:^(BOOL completed){ if(completed){ NSLog(@"Ten Thousands Counts Finished"); } }]; } and then in the called

Firebase Swift 3 Completion handler Bool

我们两清 提交于 2019-12-06 16:17:54
问题 I'm trying to write a completion handler for a function that checks if a user is a member of a team in firebase. I have a public class customFunctions in which I created a function ifUserIsMember . I seem to be a little stuck on the idea of completion handlers, and can't seem to figure out how to check the bool value on completion (if that makes sense). Here's my code for the class: import Foundation import GeoFire import FirebaseDatabase public class customFunctions { func ifUserIsMember

self refrence inside swift closure return nil some time

流过昼夜 提交于 2019-12-06 15:33:52
问题 I am accessing instance method inside closure in swift, self reference become nil in some cases which result crash my program. I tried to access using [weak self] but it failed to call the instance method when self is nil . [weak self] () -> () in 回答1: The whole point of [weak self] is to not create a reference to self (probably to avoid circular links and memory leaks) so that it can be released. If that happens, then self will be nil . You should either not use [weak self] or, better yet

Completion handler in For/In loop - swift

笑着哭i 提交于 2019-12-06 13:44:13
How can you implement a completion handler in a For/In loop ? I have an array of two CNLabeledContact called phonesArray : var myPhoneNumberArray = CNLabeledValue for item in phonesArray { let phonesArrayValue = item.value as! CNPhoneNumber let phonesArrayValueDigits = phonesArrayValue.valueForKey("digits")! print("current value: \(phonesArrayValueDigits)") // DataService.dataService.checkIfPhoneExistsInDatabase("\(phonesArrayValueDigits)") { (bool) in if bool { print("append this item") self.myPhoneNumberArray.append(item) } else { } } } print("My phonenumbers array is:") print

Using a value from Alamofire request outside the function

泪湿孤枕 提交于 2019-12-06 09:48:37
I can't seem to figure this one out: I am trying to get an error from my server (in JSON) using an Alamofire request, but I cannot get the value outside the function. This is the implementation of my function: func alamoRequest(username : String, email: String, password: String, facebook: String, completionHandler : (String?) -> Void) { var jsonValue : JSON? let URL = "http://someurl.com/login.php" let requestParameters = ["username" : username, "email" : email, "password" : password, "facebook" : facebook, "date": NSNull()]; var jsonString : String = String() Alamofire.request(.GET, URL,

iOS 7 Completion handler never gets called

那年仲夏 提交于 2019-12-06 08:38:12
问题 In the following code none of the completion handlers ever get executed. The one explanation I was able to find is this Bug in iPhone Simulator 5.1 with Xcode 4.5 using UIManagedDocument . It says that it might be a bug in iPhone simulator 5.1 . However, I've tried iPhone simulators 6.0, 6.1 and 7.0, none of them worked. I'll really appreciate your help. (By the way, I've seen this code in the Stanford iOS course, lecture 14) NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory

Completion handler swift 3 return a variable from function

半城伤御伤魂 提交于 2019-12-06 08:04:56
问题 I am confused surrounding the syntax for a completion handler in swift 3. In the function below, after parsing an xml file from a web service call, it should return a variable (an array [String:String] ). My attempt is below, but obviously it is incorrect. enum HistoryKey { case success([String:String]) case failure(String) } private func getHistoryKeys(searchterm: String, completion: @escaping () -> HistoryKey) { let url = PubmedAPI.createEsearchURL(searchString: searchterm) let request =