teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

記載内容の修正

2019/11/29 06:21

投稿

popai306
popai306

スコア157

answer CHANGED
@@ -1,8 +1,22 @@
1
- 単純に逆はなくて
1
+ これ取れませんかね
2
2
  ```
3
+ @IBAction func othersLocation(_ sender: Any)
3
-
4
+ {
5
+ //Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional valueのエラー
6
+ ref.child("users").child("userCoordinate").observeSingleEvent(of: .value, with: { (snapshot) in
7
+ let value = snapshot.value as? NSDictionary
4
- ref.child("userLatitude").child(user!)
8
+ let otherUserLatitude = value?["userLatitude"] as? String
9
+ print("ユーザー緯度:", otherUserLatitude)
10
+ })
11
+ }
12
+ ```
5
13
 
14
+ あるべきはsetValue時に
6
- 正?
15
+ ```
16
+ let userCoordinate = ["userLatitude": latitude.text]
17
+ ref.child("users").child(user!).setValue(["userCoordinate": userCoordinate])
18
+ ```
19
+ 取得するときは
20
+ ```
7
- ref.child(user!).child("userLatitude")
21
+ ref.child("users").child(user!).child("userCoordinate")...
8
22
  ```