Im trying to get all the imageURLs for all activities that are for a specific user (UserId). the content of the snapshot include the correct entries, however the imageURL is not appended to imageArray. What am I doing wrong?
// Get all images for a specific user
func getImagesForUser(userId:String, handler: @escaping (_ imageArray: [String]) -> ()) {
var imageArray = [String]()
REF_ACTIVITY.queryOrdered(byChild: "userId").queryEqual(toValue: userId).observe(.value, with: { snapshot in
dump(snapshot)
guard let data = snapshot.value as? NSDictionary else { print("else was returned"); return }
let imageURL = data["imageURL"] as? String ?? ""
imageArray.append(imageURL)
handler(imageArray)
})
}
Output from dump(snap)
Snap (-L2RDXTKANzD8YGpPl92) {
gearId = asfasfsf;
imageCount = 3;
imageURLs = {
1 = "http://www.foo.com";
2 = "http://www.foo2.com";
3 = "http://www.foo3.com";
};
killCount = 10;
kills = 12;
likeCount = 2;
likes = {
fas86q39rasf = 1;
};
userId = NhZZGwJQCGe2OGaNTwGvpPuQKNA2;
}
Snap (-L2RDXTKANzD8YGpPl92) {
gearId = asfasfsf;
imageCount = 3;
imageURLs = {
1 = "http://www.foo.com";
2 = "http://www.foo2.com";
3 = "http://www.foo3.com";
};
killCount = 10;
kills = 12;
likeCount = 2;
likes = {
fas86q39rasf = 1;
};
userId = NhZZGwJQCGe2OGaNTwGvpPuQKNA2;
}
Update - output of Dict
24 elements
▿ 0 : 2 elements
- key : "commentCount"
- value : 1
// removed some info
...
▿ 12 : 2 elements
- key : "imageURLs"
▿ value : 4 elements
- 0 : <null>
- 1 : https://firebasestorage.googleapis.com/v0/b/shoota-179610.appspot.com/o/activity_image%2FCA6F4C93-8F5F-456C-9FD6-F2EACC444739?alt=media&token=522d957b-dedf-4bdc-9cbc-1de581284393
- 2 : https://firebasestorage.googleapis.com/v0/b/shoota-179610.appspot.com/o/activity_image%2FCA6F4C93-8F5F-456C-9FD6-F2EACC444739?alt=media&token=522d957b-dedf-4bdc-9cbc-1de581284393
- 3 : https://firebasestorage.googleapis.com/v0/b/shoota-179610.appspot.com/o/activity_image%2FCA6F4C93-8F5F-456C-9FD6-F2EACC444739?alt=media&token=522d957b-dedf-4bdc-9cbc-1de581284393
▿ 13 : 2 elements
- key : "imageURL"
- value : https://firebasestorage.googleapis.com/v0/b/shoota-179610.appspot.com/o/activity_image%2FCA6F4C93-8F5F-456C-9FD6-F2EACC444739?alt=media&token=522d957b-dedf-4bdc-9cbc-1de581284393
▿ 14 : 2 elements
- key : "killCount"
- value : 10