vendredi 10 mars 2017

Random Image Generator Swift and Firebase

I've been learning Swift by building my own app (Thanks Stack Overflow!). I apologize if the answer is obvious. I've been struggling with this for awhile now. One of the key features of my app is a random image generator. I've found code for a random image generator in my Udemy class, but unfortunately it references Parse instead of Firebase. (See below):

func updateImage() {
Let query = PFUser.query()
query?.limit = 1
query?.findObjectsInBackground(block: { (objects, error) in
if let users = objects {
    for object in users {
        if let user= object as? PFUser {
            let imageFile = user[“photo”] as! PFFile
imageFile.getDataInBackground(block: {data, error} in
    if let imageData = data {
        self.imageView.image = UIImage(data: imageData)
    }
  }
  }
}
}

The process for the view controller is the user sees a new image, rates it and presses button to submit it. When button pressed, rating submitted and new image is sourced from Firebase Storage. Basically, I'm looking to use the above code by converting it to Firebase approved or simply some insight on how to build a random image generator from scratch for Firebase and Swift 3. I'm completely at a stopping point so any help would be greatly appreciated. Thanks much.

Aucun commentaire:

Enregistrer un commentaire