Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var country = ["USA", "CANADA"]
- countries
- Canada
- states
- Alberta
- British Columbia
- USA
- states
- Alabama
- Arkansas
- import UIKit
- import FirebaseDatabase
- class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
- @IBOutlet weak var countryPicker: UIPickerView!
- //let country = ["USA", "Canada"] I am no longer using this hardcoded array
- var countrySelected = String()
- var action = 0
- override func viewDidLoad() {
- super.viewDidLoad()
- //this is where I reach out to the database
- let database = Database.database().reference()
- database.child("countries").observeSingleEvent(of: .value) { (Snapshot) in
- print(Snapshot)
- }
- //add code here that takes the snapshot and appends the the array below
- var country = string()
- countrySelected = country[0]
- countryPicker.selectRow(action, inComponent: 0, animated: false)
- //print(countrySelected)
- }
- func numberOfComponents(in pickerView: UIPickerView) -> Int {
- return 1
- }
- func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
- return country.count
- }
- func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
- return country[row]
- }
- func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
- countrySelected = country[row]
- action = country.firstIndex(of: countrySelected)!
- //print(countrySelected)
- }
Add Comment
Please, Sign In to add comment