1

As i read in the documentation i can access single url in firebase storage like this:

`// Create a reference to the file you want to download 
let starsRef = storageRef.child("images/stars.jpg") 
// Fetch the download URL starsRef.downloadURL { url, error in 
   if let error = error { 
   // Handle any errors } 
   else { 
   // Get the download URL for 'images/stars.jpg' 
} }` 

However, i have many files there, so how can i skip giving direct path and instead iterate through all files in the given directory?

Thanks for tips.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
misi06
  • 259
  • 1
  • 8
  • 16
  • 1
    Possible duplicate of [How to get an array with all pictures?](https://stackoverflow.com/questions/37335102/how-to-get-an-array-with-all-pictures) – Mike McDonald Oct 20 '17 at 18:28

1 Answers1

0

DownloadURL takes single string at a time. In case you want to show all the files inside a folder to a tableview like me, here is the full code:

   import UIKit import Firebase

My very First View Controller-

   class FolderList: UIViewController {
       var folderList: [StorageReference]?
        lazy var storage = Storage.storage()

       @IBOutlet weak var tableView : UITableView!

       override func viewDidLoad() {
           super.viewDidLoad()
   self.storage.reference().child("TestFolder").listAll(completion: {
   (result,error) in
               print("result is \(result)")
               self.folderList = result.items
               DispatchQueue.main.async {
                   self.tableView.reloadData()
               }
           })
       } }
   extension FolderList : UITableViewDataSource {
       func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
           return folderList?.count ?? 0
       }

       func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
           guard let cell = tableView.dequeueReusableCell(withIdentifier: "FolderListCell", for:
   indexPath) as? FolderListCell else {return UITableViewCell()}
           cell.itemName.text = folderList?[indexPath.row].name
           return cell
       }

       func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
           return 64.0
       } }

   extension FolderList : UITableViewDelegate {
       func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
           let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
           guard let downloadVC = storyBoard.instantiateViewController(withIdentifier:
   "DownloadedItemView") as? DownloadedItemView else {
               return
           }
           downloadVC.storageRef = folderList?[indexPath.row]
           self.navigationController?.pushViewController(downloadVC, animated: true)
       } 
}

You each cell:

   class FolderListCell: UITableViewCell {

       @IBOutlet weak var itemName : UILabel!

   }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Rajlakshmi
  • 61
  • 1
  • 1
  • 6
  • Please take a moment to read through the [editing help](//stackoverflow.com/editing-help) in the [help]. Formatting on Stack Overflow is different than other sites. – Dharman Nov 14 '19 at 15:22