2016-09-05 12 views
-4

私は以下の2つのテーブルを作成しました。テーブルフレンドを選択しての名前を表としたいですか?誰でも私を手助けすることができます例えば迅速に感謝してください。迅速な火災基盤の例

id 
user_id 
friend_id 
+1

は_「私のコードを教えてください」:-)スタックオーバーフローへようこそパスを観察し、このサイトが動作する方法はありません。あなた自身の努力を示し、あなたの問題を説明してください。見てください[質問] – JimHawkins

答えて

0

表のユーザー

id 
name 
email 

表の友人があなたのリアルタイムデータベースは、次のようになります。

{ 
    "users": { 
     "1": { 
      "name": "John Doe", 
      "email": "[email protected]" 
     }, 
     "2": { 
      "name": "Jane Doe", 
      "email": "[email protected]" 
     } 
    }, 
    "user-friends": { 
     "1": { 
      "2": true 
     }, 
     "2": { 
      "1": true 
     } 
    } 
} 

ジョンの友人を得るために、私たちは_ /user-friends/1

let uid = 1 // the uid of the user we want the friends of 
let ref = FIRDatabase.database().reference().child('user-friends/\(uid)') 

ref.observeEventType(.ChildAdded, block: { snapshot in 

    let uid = snapshot.key // the uid of a user who is John's friend 
    let ref = FIRDatabase.database().reference().child('users/\(uid)') 

    ref.observeSingleEventOfType(.Value, block: { snapshot in 
     if let json = snapshot.value as? [String:AnyObject] { 
      print(json["name"]) 
     } 
    }) 
}) 
+0

あなたの助けをありがとう – user2502099

関連する問題