Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift firebase read key in autoKey

//https://stackoverflow.com/questions/53350869/swift-fetching-all-users-to-an-array
//MVC - MVVM
//First Step
struct User{
    var id:String
    var username:String?
    var occupation:String?
    var age:Int?
    var bio:String?
    var email:String?
}


//Second Step
let query = self.ref.child("Users").queryOrdered(byChild: "email")
    query.observeSingleEvent(of: .value) {
        (snapshot) in
        for child in snapshot.children.allObjects as! [DataSnapshot] {
            let id = child.key
          //optional Line for sub childs
          //let key  = child.childSnapshot(forPath: "SubChild")//optional
            
          let value = child.value as? NSDictionary//let value = key.value as? NSDictionary
            let username = value?["Username"] as? String
            let occupation = value?["Occupation"] as? String
            let age = value?["Age"] as? Int
            let bio = value?["Bio"] as? String
            let email = value?["email"] as? String

            let user = User(id: id, username: username, occupation: occupation, age: age, bio: bio, email: email)

            self.usersArray.append(user)
        }
        completion("Users list fetched")
    }
Comment

PREVIOUS NEXT
Code Example
Swift :: how to disable uitableview selection in swift 
Swift :: remove child from firebase swift 
Swift :: swift rotate text 90 degrees 
Swift :: remove checkmark when selecting the cell again swift 5 
Swift :: pop view swiftui 
Swift :: swiftui text alignment 
Swift :: detect binding valu change swiftui 
Swift :: use timer swift 
Swift :: use of map instad of for loop 
Swift :: swift do catch 
Swift :: return multiple values from a function swift 
Swift :: swiftui play mp3 
Swift :: swift remove tableview cell 
Swift :: using swipe gesture recognizer swift 
Swift :: swift collection view check if you are at the bottom 
Swift :: an in swift 
Swift :: swift url request 
Swift :: manifest merger failed in android studio 
Swift :: swift contains 
Swift :: how to covert a string into a float in swift 
Swift :: how to change background color of stackview swift 
Swift :: swiftui font add 
Swift :: swift add navigation bar 
Swift :: swift extension Array with element 
Swift :: Swift Swift Function Return Values 
Swift :: two variable sum in swift 
Swift :: table view content size not return correctly 
Swift :: Swift continue with while loop 
Swift :: swift singleton 
Swift :: swift string interpolation 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =