Skip to content

Instantly share code, notes, and snippets.

@gayapedro
Last active July 8, 2017 19:04
Show Gist options
  • Select an option

  • Save gayapedro/ac49a8c5f761aec2c2af7b8f966e1e60 to your computer and use it in GitHub Desktop.

Select an option

Save gayapedro/ac49a8c5f761aec2c2af7b8f966e1e60 to your computer and use it in GitHub Desktop.
Busca DB Firebase
//
// ViewController.swift
// TesteFirebase
//
// Created by Pedro Gaya on 07/07/17.
// Copyright © 2017 GayaSolutions. All rights reserved.
//
import UIKit
import FirebaseDatabase
class ViewController: UIViewController {
@IBOutlet weak var labelPontuacao: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let database = Database.database().reference().child("usuarios")
database.queryStarting(atValue: "Me", childKey: "nome").queryEnding(atValue: "Z"+"\u{F8FF}", childKey: "nome").queryOrdered(byChild: "nome").observe(DataEventType.value, with: { (dados) in
for nomes in dados.children.allObjects as! [DataSnapshot] {
let objeto = nomes.value as! [String: AnyObject]
let idade = objeto["idade"]!
let nome = objeto["nome"]!
print("-----")
print(idade)
print (nome)
print("-----")
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
let database = Database.database().reference().child("medicamentos")
database.queryOrdered(byChild: "nome").observe(DataEventType.value, with: { (dados) in
for nomes in dados.children.allObjects as! [DataSnapshot] {
let objeto = nomes.value as! [String: AnyObject]
let nome = objeto["nome"]!
print("-----")
print (nome)
print("-----")
}
})
@gayapedro
Copy link
Author

"auth != null"

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