我正在运行下面的代码,以查看打开应用程序的用户是否已经登录,然后检查他们是否设置了个人资料。我在检查从个人资料检查返回的空值时遇到了问题。
override func viewDidLoad() {
super.viewDidLoad()
//Check to see if user is already logged in
//by checking Firebase to see if authData is not nil
if ref.authData != nil {
//If user is already logged in, get their uid.
//Then check Firebase to see if the uid already has a profile set up
let uid = ref.authData.uid
ref.queryOrderedByChild("uid").queryEqualToValue(uid).observeSingleEventOfType(.Value, withBlock: { snapshot in
let profile = snapshot.value
print(profile)
})
在最后一行中,当我打印(profile)时,要么会得到个人资料信息,要么会
<null>
我该如何检查这个值?
if profile == nil
无法正常工作
如果我执行
let profile = snapshot.value as? String
首先,即使存在快照值,它始终返回nil。