ユーザーIDに基づいてユーザーを検索するクエリがあります。Firebase snapshot.keyは実際のキーを返していないのですか?
usersRef.queryOrderedByChild("email").queryEqualToValue(email).observeEventType(.Value, withBlock: { snapshot in
if snapshot.exists() {
print("user exists")
print(snapshot.key)
クエリが正しいユーザを返すが、ラインprint(snapshot.key)
は文字通り単語「ユーザー」、およびない実際のユーザIDを返します。 print(snapshot)
戻り、次のユーザー:
Snap (users) {
DELyncz9ZmTtBIKfbNYXtbhUADD2 = {
email = "[email protected]";
"first_name" = test;
"last_name" = test;
};
どのように私はDELyncz9ZmTtBIKfbNYXtbhUADD2
を得ることができますか? let email = child.value["email"]
を使用してメールを受け取ることはできますが、名前付き属性ではないため、鍵を取得できません。
ありがとうございます!
編集:フランクの答えのおかげでコードが更新されました。あなたが場所でクエリを実行するとambiguous use of key
query.observeEventType(.Value, withBlock: { snapshot in
print(snapshot.key)
if snapshot.exists() {
print("user exists")
for child in snapshot.children {
print(child.key)
はそれを考え出しました! '単にkey = child.keyをStringとしましょう '。再度、感謝します!! – winston