在快速使用Firebase时,我遇到了一个非常奇怪的问题。似乎脚本可以继续执行而无需等待完成块完成。这就是我的意思:
我有一个功能:
func create_user(email:String, password:String) -> Bool{
var create_suc = false
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
if let error = error{
// Error creating new user.
create_suc = false
print("In fail closure: \(create_suc)")
}else{
// Create successfully.
create_suc = true
print("In success closure: \(create_suc)")
}
}
print("Before return: \(create_suc)")
return create_suc
}
以及调用此函数的上下文:
@IBAction func sign_up(_ sender: UIButton) {
let result = create_user(email: acc_email.text!, password: acc_password.text!)
print("Create successfully: \(result)")
我得到的结果很奇怪:
**Before return: false**
**Create successfully: false**
2018-08-26 16:41:55.313457-0700 chat_app[251:9301] TIC Read Status [2:0x0]: 1:57
2018-08-26 16:41:55.313611-0700 chat_app[251:9301] TIC Read Status [2:0x0]: 1:57
2018-08-26 16:41:56.013564-0700 chat_app[251:9300] TIC Read Status [3:0x0]: 1:57
2018-08-26 16:41:56.013721-0700 chat_app[251:9300] TIC Read Status [3:0x0]: 1:57
**In success closure: true**
答案 0 :(得分:2)
任务异步并不奇怪。
string url = "EntityDefinitions(LogicalName='contact')/Attributes(LogicalName='new_country')/Microsoft.Dynamics.CRM.PicklistAttributeMetadata? $select=LogicalName&$expand=OptionSet($select=Options)";
var countrylist = await client .FindEntriesAsync(url);