输入“用户?”没有会员UID(Swift 3,Firebase)

时间:2016-11-02 18:02:43

标签: swift firebase swift3 firebase-authentication

我正在使用Firebase设置登录页面,我遇到了一个错误,uid无法识别。这是我的代码:

    FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (FIRUser,error) in

        if error != nil {
            print(error)
            return

        }

        guard let uid = user?.uid else {
            return
        }

我也无法命令点击进入FIRUser,但是如果我摆脱了保护声明,身份验证就可以正常运行。

我已导入Firebase和FirebaseDatabase(无法导入FirebaseAuth,它已被删除),所以不是这样。

知道为什么我无法访问FIRUser并使用uid

1 个答案:

答案 0 :(得分:1)

您需要在闭包中创建变量import time import json import string import numpy as np ############################# GENERATE RANDOM DATA ############################# #letters = list(string.ascii_lowercase) #random_data = ["""{"price": %d, "owner": "%s"}""" % (np.random.randint(1, 1000), # ''.join(np.random.choice(letters, 6, replace=False))) for x # in xrange(1000000)] # #with open('pseudo_json.txt', 'w') as outfile: # for line in random_data: # outfile.write(str(line) +'\n') time1 = time.time() #################################### METHOD 1 ################################## running_max = 0 with open('pseudo_json.txt', 'r') as infile: for line in infile: price = json.loads(line)['price'] if price > running_max: running_max = price time2 = time.time() #################################### METHOD 2 ################################## with open("pseudo_json.txt", 'r') as f: allcontent = [] for line in f: allcontent.append(json.loads(line)) the_max = (max(allcontent, key=lambda x: x['price'])) time3 = time.time() ##################################### METHOD 3 ############################## the_max = 0 with open("pseudo_json.txt", 'r') as f: the_max = (max(f, key=lambda x: json.loads(x)['price'])) time4 = time.time() #################################### ORIGINAL ################################## with open("pseudo_json.txt", 'r') as infile: allcontent = [] for line in infile: allcontent.append(json.loads(line)) values = [] for line in allcontent: for key,value in line.items(): values.append(value) the_max = max(values) time5 = time.time() ################################# READING FILE ################################# with open("pseudo_json.txt", 'r') as infile: for line in infile: pass time6 = time.time() ################################### RESULTS #################################### print "Without storage and max took: {}".format(time2 - time1) print "With storage and using max took: {}".format(time3-time2) print "Without storage but using max took: {}".format(time4 - time3) print "Original took: {}".format(time5 - time4) print "Reading file took: {}".format(time6 - time5) 。改为将此功能重写为此。

user