Firebase Swift - 密钥的模糊使用

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

标签: swift firebase

在Firebase(Swift)中,我只需要将结果节点集的键拉为:

print((detailData as AnyObject).key)

过去几个月以来一直工作,现在出现错误Ambiguous use of "key",应用程序无法编译

如何访问节点的密钥?

dataDetail:

Snap (3MopWYcckIc5OYZkBBUVwghz2) {
    confirmed = 1;
    phoneNumber = 14024464289;
    selfSendRequest = 1;
    timeInvited = "2016-06-04 15:34:43";
    userName = aUserName;
}

2 个答案:

答案 0 :(得分:1)

如果 detailData 是您从Firebase收到的快照,则可以尝试: -

if let snapDict = detailData.value as? [String:AnyObject]{

     let key = detalData.key // your key
     print(snapDict)
    }

答案 1 :(得分:1)

这应该有效:

let key = (snapshot as! FIRDataSnapshot).key