Skip to content

Instantly share code, notes, and snippets.

@ayoub-9
Created February 24, 2019 14:20
Show Gist options
  • Save ayoub-9/13868b6f26fc9001b504b69d1a33013d to your computer and use it in GitHub Desktop.
Save ayoub-9/13868b6f26fc9001b504b69d1a33013d to your computer and use it in GitHub Desktop.
var dbRef:DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
dbRef = Database.database().reference()
let myEps = dbRef.child("users").child("InfoUser").child("Eps")
myEps.observeSingleEvent(of: .value) { (snapshot) in
let enumrator = snapshot.children
while let myEpss = enumrator.nextObject() as? DataSnapshot {
let item = myEpss.value as AnyObject
print(item)
}
}
}
@ayoub-9
Copy link
Author

ayoub-9 commented Feb 24, 2019

import UIKit
import Firebase
import FirebaseDatabase

class EPISODESViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var MyTableView: UITableView!


var itemsLoded = [AnyObject]()

override func viewDidLoad() {
    super.viewDidLoad()

    FetchPosts()
    
    

}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
    
    return itemsLoded.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    
    cell.textLabel?.text = "\(itemsLoded[indexPath.row])"
    
    return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
    print("\(itemsLoded[indexPath.row])")
}


func FetchPosts(){
    
    
    var dbRef:DatabaseReference!


    dbRef = Database.database().reference()
    
    
    
    
    Database.database().reference().child("DramaKorea").observe(.childAdded) { (snapshot) in
        
        
       let postId = snapshot.key
        
        dbRef.child("DramaKorea").child(postId).observe(.value, with: { (snapshot2) in
            
            
          let AllEpisodes = dbRef.child("DramaKorea").child("-LZUxpD0Ym_U39lRAsrB").child("Episods")
            
         
            AllEpisodes.observeSingleEvent(of: .value, with: { (snapshot3) in
                
                
                self.itemsLoded.removeAll()
                
                let Grabb = snapshot3.children
                
                
                while let epsiods = Grabb.nextObject() as? DataSnapshot {
                    
                    
                    let items = epsiods.value as AnyObject
                    
                    self.itemsLoded.append(items)
                    
        
                }
                
                self.itemsLoded = self.itemsLoded.reversed()
                self.MyTableView.reloadData()
            })
            
        })
        
    }
    
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment