##前提
初めてswift, Firebaseでiosアプリを作ってます。
##問題
Firebase に子ノードを作れないので、怪しい部分を調べて見つけたのですが、どう読んで良いか分からず解決できない
##CODE
swift
1print("1") 2print("Api.User.CURRENT_USER?.uid: ((Api.User.CURRENT_USER?.uid)!)") 3Database.database().reference().child("notification").child((Api.User.CURRENT_USER?.uid)!).observeSingleEvent(of: .value, with: { (snapshot) in 4 print("snapshot.children: (snapshot.children)") 5 print("snapshot.children.allObjects: (snapshot.children.allObjects)") 6 let arraySnapshot = snapshot.children.allObjects as! [DataSnapshot] 7 arraySnapshot.forEach({ (child) in 8 print("-------child.key: (child.key)") 9 }) 10}) 11print("2")
##MESSAGE
1 Api.User.CURRENT_USER?.uid: DAn4t6ZqSMfjlUNeUpaDbIQNSCl2 2 snapshot.children: <FTransformedEnumerator: 0x600003aebba0> snapshot.children.allObjects: []
これは、
Firebaseに接続できているけど、snapshotの値が帰ってきていない
ということでしょうか?
また、どうやって解決したら良いでしょうか?
すみませんが、よろしくお願いします。
##開発環境
MacOS Mojave 10.14
Xcode 10.0
Swift 3.0
##書き込みデータのCODE
swift
1Database.database().reference().child((Api.User.CURRENT_USER!.uid)).observeSingleEvent(of: .value, with: { snapshot in 2let arraySnapshot = snapshot.children.allObjects as! [DataSnapshot] 3 4// 書き込みデータ 5arraySnapshot.forEach({ (child) in 6guard let postId = newPostId else { return } 7let newNotificationId = Api.Notification.REF_NOTIFICATION.child(child.key).childByAutoId().key 8guard let notificationId = newNotificationId else { return } 9let newNotificationReference = Api.Notification.REF_NOTIFICATION.child(child.key).child(notificationId) 10newNotificationReference.setValue(["from": Api.User.CURRENT_USER!.uid, "type": "feed", "objectId": postId, "timestamp": timestamp]) 11}) 12})
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。