我在VC中开发了三个函数,它们如下:
第一个,即checkUsernameOrEmailTaken在其自身内部调用另外两个,并通过完成返回结果,指示采用哪一个(基于int值,其中1 =电子邮件,2 =用户名。这是代码:< / p>
func checkUsernameOrEmailTaken(username: String, email:String, completion: (result: Int) -> Void)
{
/*This function checks the result of both functions, checkEmailTaken and checkUsernameTaken*/
/*
return 1 = email is taken
return 2 = username is taken
*/
var inputTaken:Int = 0
print("Inside CheckUsernameOrEmailTaken")
self.checkEmailTaken(email, completion: { (result)->Void in
print("Finish Checking Email Taken")
if(result == true)
{
/*Email is taken*/
print("Email Taken")
inputTaken = 1
completion(result: inputTaken)
}else{
/*Email not taken*/
print("Email Available")
self.checkUsernameTaken(username, completion: { (result)->Void in
if(result == true)
{
inputTaken = 2
completion(result: inputTaken)
}else{
completion(result: 0)
}
})
}
})
}
func checkEmailTaken(email:String, completion: (result: Bool) -> Void)
{
print("Inside CheckEmailTaken")
//let reference = Firebase(url:"https://something.firebaseio.com/users/")
reference.queryOrderedByChild("email").queryEqualToValue("\(email)").observeEventType(.ChildAdded, withBlock: { snapshot in
if (snapshot.value["email"] != nil) {
print("Inside CheckEmailTaken ---- Taken")
completion(result: true)
}else{
print("Inside CheckEmailTaken ----- Available")
completion(result: false)
}
})
}
func checkUsernameTaken(username: String, completion: (result: Bool) -> Void)
{
//let reference = Firebase(url:"https://something.firebaseio.com/users/")
reference.queryOrderedByChild("username").queryEqualToValue("\(username)").observeEventType(.ChildAdded, withBlock: { snapshot in
if (snapshot.value["username"] != nil) {
completion(result: true)
}else{
completion(result: false)
}
})
}
我有许多打印声明要知道,直到执行继续。我只进入控制台:
Inside CheckUsernameOrEmailTaken
Inside CheckEmailTaken
我的进度微调器并没有因为呼叫没有继续而消失。似乎它正在继续执行但没有显示任何动作。在后端,我有
->users
->6dd077ac-dsds-4060-ac4f-dsdsdsdsdsds1
email: "kleina@outlook.com"
mobile: "32322332"
name: "Kleina"
username: "someone"
我在文本字段中的输入是不同的电子邮件,但是同一个用户名,即某人......并且它一直在继续。如果我尝试测试电子邮件的存在,它可以工作并显示电子邮件已被删除。请让我知道哪里出错...我使用Firebase编写的第一个函数..
答案 0 :(得分:1)
还请在Firebase查询中插入错误块以查看是否有错误:
ref.observeEventType(.Value, withBlock: { snapshot in
println(snapshot.value)
}, withCancelBlock: { error in
println(error.description)
})
如果没有与db的连接,您也会收到错误。