Firebase Swift 3 get list of child in a array
Try this:-
ref.child("").observe(.childAdded, with: { (snapshot) in
var newItems = [FIRDataSnapshot]()
for item in snapshot.children {
newItems.append(item as! FIRDataSnapshot)
}
})
how can i get array from child and save in struct from firebase in swift
Solved! Thanks so much all. I could find the solution
struct User {
let fullname: String
let location: String
let uid: String
// i finally create a simple array
var tripList: [Int]
init(uid: String, dictionary: [String: Any]) {
self.uid = uid
self.fullname = dictionary["fullname"] as? String ?? ""
self.location = dictionary["location"] as? String ?? ""
var arrayTripsAux = [Int]()
if let a_trips = dictionary["a_trips"] as? [String: [String:Int]]{
for t in a_trips.values{
arrayTripsAux.append(t["id"] ?? 0)
}
} else {
arrayTripsAux.append(0)
}
// return childs in array
self.tripList = arrayTripsAux
}
Find Firebase Child from Array Values - xcode 8 / swift 3
Here's how you'd get started, once you have your parsed data you can use different methods to filter it which you can look up through different stackoverflow questions answered in the past.
let dbRef = FIRDatabase.database().reference.child("friends")
dbRef.observeSingleEvent(of: .value, with: { snapshot in
if let data = snapshot.value as? [String: [String: String]] {
for user in data {
// You'll now have a dictionary with neatly formatted values you can filter
}
}
})
Firebase - retrieve all child keys and child values into separate arrays in Swift
Snapshots have two properties.
snapshot.key
snapshot.value
When using an observer with .value. all of the key: value children are returned in the snapshot. They can be iterated over to capture each key: value pair like this.
ref.observeSingleEvent(of: .value, with: { (snapshot) in
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key
let value = snap.value
print("key = \(key) value = \(value!)")
}
})
Keep in mind that the value property could be a string, number, array or another dictionary (snapshot). In the original question it's a String.
Get children of child nodes from firebase (swift 3)
try this:-
func loadImages (){
Database.database().reference(withPath:
"Студии").child("Дубаи").observe(.value, with: { (snapShot) in
if snapShot.exists() {
let array:NSArray = snapShot.children.allObjects as NSArray
for child in array {
let snap = child as! DataSnapshot
if snap.value is NSDictionary {
let data:NSDictionary = snap.value as! NSDictionary
if let dict = data.value(forKey: "Images") {
let dictImage:NSDictionary = dict as!
NSDictionary
if let image = dictImage["image1"] {
print(image)
}
}
}
// newImage1.append(url2)
}
}
})
}
firebase child values as string in array to populate a picker swift 3
You need to reload the pickerView
components to change it with new dataSource array.
let dbRef1 = FIRDatabase.database().reference().child("Live Scoring Male")
dbRef1.observe(.childAdded, with: { snapshot in
if let dic = snapshot.value as? [String:Any], let name = dic["name"] as? String {
self.compArray.append(name)
print("\(name)")
//Reload the pickerView components
self.pickerView.reloadAllComponents()
//Or you can reload the pickerView's specific component
self.pickerView.reloadComponent(0)
}
})
Retrieving an array of children in Firebase using Swift
You could do something like:
var ref = Firebase(url: "https://<yourApp>.firebaseio.com/restaurants/")
ref.observeEventType(.Value, withBlock: {
snapshot in
var restaurantNames = [String]()
for restaurant in snapshot.children {
restaurantNames.append(restaurant.key)
}
print(restaurantNames)
})
restaurantNames will have the array you asked for. You are still receiving the complete restaurant objects from firebase, but just using their keys(names).
Receiving a Firebase snapshot from a child with an array SWIFT
Try This
var post = [String]()
ref.observe(.value, with: { (snapshot) in
for item in snapshot.children{
self.post.append((item as AnyObject).key)
}
})
Then you print "post" and you will get ["170802120618", "170802101427"]
Related Topics
Saving an Array of Nsurl to Nsuserdefaults
Actions Assigned to Nsmenuitem Dont Seem to Work
List Is Not Conforming to Encodable
How to Call Https Url in UIwebview (Swift)
How to Provide Default Implementation of an Objective-C Protocol in a Swift Protocol Extension
Underlying Type for Tuple in Swift
How to Fill Triangle in Swift Using Core Graphics
Need Clarification on Typealias Syntax in Swift
Swift: Switch Statement Fallthrough Behavior
Aurendercallbackstruct in Swift
Swift Unsafemutablepointer & Unsafemutablepointer<Unsafepointer<Sometype>>
Automatically Reload Tableviewcontroller on Rewind