我正在運行下面的代碼以查看打開該應用程序的用戶是否已登錄,然後檢查他們是否設置了配置文件。我無法檢查來自檔檢查Firebase檢查空值(Swift)
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)
})
返回在最後一行時,我打印(配置文件)的空值的值,我要麼得到的資料信息,或
<null>
如何我檢查這個值嗎?
if profile == nil
不起作用
如果我做
let profile = snapshot.value as? String
第一,那麼它總是返回零即使有一個snapshot.value
嘗試,如果(snapshot.value!=無){}或者(snapshot.value作爲!NSObject的!=無){} –
謝謝shrikant,但第一有同樣的問題。第二個建議給我「值類型'NSObject永遠不可爲零」錯誤 – FortuneFaded
什麼是快照的數據類型? –