0

I finally was able to pull an array of images from Parse.com after fiddling with tutorials.

From that array I want to throw it on an image view via next random image with a swipe gesture:

var query = PFQuery(className:"cats")
query.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in
    if error == nil {
        // The find succeeded.
        for object in objects! {
            // Update - replaced as with as!
            self.imageFiles.append(object as! PFObject)
            println(self.imageFiles)
            self.view.addGestureRecognizer(rightSwipe)
            }
        } else {
            // Log details of the failure
            println(error)
        }
    }
}

The println(self.imageFiles) actually shows the array of files which is great, what I'm having issues with is using the random generator.

Still new to syntax, I was trying to do like imageview.image = imageFiles[0] or something like that to just display one of the images in the array. Not really sure the syntax though.

I'm guessing once I get that it would be imageview.image = imageFiles[RandomNumber] or the equivalent.

for the swipe part I think I got that under control

Edit

ok I have:

let randomNumber = imageFiles[Int(arc4random_uniform(UInt32(imageFiles.count)))]
println(randomNumber)

and the println gives me a random image file from the array.

How do I put that into the image view?

EDIT just tried:

for randomNumber in imageFiles {
    self.ImageView.image = randomNumber
}

and got:

cannot assign a value type pfobject to a value type of uiimage

self.ImageView.image = UIImage(data: randomNumber)

also gives me an error can't have data: PFObject

Lucas Huang
  • 3,998
  • 3
  • 20
  • 29
dcarney999
  • 51
  • 7
  • 1
    See http://stackoverflow.com/questions/24007129/how-does-one-generate-a-random-number-in-apples-swift-language for generating a random integer in Swift. Then just use that with your imageFiles array as you described. – Connor Neville Jul 17 '15 at 04:05
  • Could you provide a print screen of your "cats" database in Parse? This will help to determine how you will actually retrieve the image itself, because right now you are just retrieving data about a "cat" object, thus a reference to the image – Kumuluzz Jul 17 '15 at 10:56
  • Its just a list of 10 images. I have retreaved them Im just not sure how to display an element of the array. Also I know the method for random that is not the issue. I am not sure how to put it into an image view. – dcarney999 Jul 17 '15 at 17:56

0 Answers0