Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase storage. Download array of images

I am trying to download some images from Firebase Storage folder and pus it into my model Rules Firebase Folder Images in folder

My model is here. Instead of String (1,2,3,4,5) i have to use images from folder that has the same String names

struct ImageModel {
    var images: String
    var index: Int
    var imageLabel: String
    var description: String
    var comment = [String]()
}

class Model {
   static var imageModel = [
        ImageModel(images: "1", index: 0, imageLabel: "MDA", description: "description", comment: []),
        ImageModel(images: "2", index: 1, imageLabel: "Picture!", description: "some description.", comment: []),
        ImageModel(images: "3", index: 2, imageLabel: "What is this??", description: "description", comment: []),
        ImageModel(images: "4", index: 3, imageLabel: "A long named picture", description: "description", comment: []),
    ]
}

I have found how to write a request

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

func uploadMedia() {
        let storageRef = Storage.storage().reference().child("pictures")
        let megaByte = Int64(1 * 1024 * 1024)
        
        storageRef.getData(maxSize: megaByte) { (data, error) in
            guard let data = data else { return }
            let image = UIImage(data: data)
            for i in Model.imageModel {
                i.images = image
            }
        }
    }

But it has some errors, like

Cannot assign to property: i is a let constant … and …. Cannot assign value of type UIImage? to type String

How do i change my model or request?

I use my model in Collection View Cell

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: CollectionViewCell.identifier, for: indexPath) as? CollectionViewCell else { return UICollectionViewCell() }
        cell.configureCollectionViewCell(picture: UIImage(named: String(Model.imageModel[indexPath.row].images))!, imageLabel: Model.imageModel[indexPath.row].imageLabel)
        return cell
    }

>Solution :

You want to access the array of images directly, not the reference to each item.

for (index, i) in Model.imageModel.enumerated() {
    Model.imageModel[index].images = image
}

Also, your images property accepts a String, as defined here:

var images: String

But you’re trying to assign it a UIImage. I’m not sure what you’re trying to add to the ImageModel, maybe you can elaborate?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading